ASP.Net MVC 自定义模型绑定解释 [英] ASP.Net MVC Custom Model Binding explanation

查看:31
本文介绍了ASP.Net MVC 自定义模型绑定解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我在哪里可以找到构建自定义模型绑定器的教程.

Is anyone aware of where I can find a tutorial for building a custom model binder.

我发现使用带有 EntitySets 的默认模型绑定器存在几个问题(在创建新对象和在编辑对象上创建重复项时不填充),并发现我的 UI 与我的模型不完全匹配(例如格式为hh:mm"的时间字段am"与时间跨度不匹配).因此,我想看看创建自定义模型绑定器是否是更好的解决方案.我找到了几个例子:here此处.第一个是我认为已经过时,第二个并没有真正解释发生了什么.

I have found several issues using the default model binder with EntitySets (not populating when creating new objects and creating duplicates on editing objects) and find that my UI doesn't match my model exactly (e.g. time fields formated "hh:mm am" do not match with a timespan). I therefore want to look at whether creating a custom model binder is a better solution. I have found a couple of examples: here and here. The first is I believe out of date and the second doesn't really explain what is going on.

我的主要问题是我不完全理解 BindModel 方法的 ControllerContext 和 ModelBindingContext 实际上是什么,即它们与控制器和模型的关系.

My main problem is that I don't fully understand what the ControllerContext and ModelBindingContext Of the BindModel method actually are, i.e. how they relate to the controller and model.

如果有人向我指出教程或可以查看 dave hayden 的帖子,向我展示当前 MVC 实现的效果.

I would be grateful if someone point me to a tutorial or could take a look at the dave hayden's post and show me how it might look with the current implementation of MVC.

推荐答案

我现在实际上找到了以下两篇文章,它们是对模型绑定的一个很好的总结:

I've actually now found the following two posts which a good summary of model binding:

http://odetocode.com/Blogs/scott/存档/2009/04/27/12788.aspx

http://odetocode.com/Blogs/scott/存档/2009/05/05/12801.aspx

这篇关于ASP.Net MVC 自定义模型绑定解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆