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

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

问题描述

是任何人都知道在哪里可以找到为构建自定义模型粘合剂的教程。

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

我发现使用带有EntitySets(创建新的对象和创建上编辑对象重复时不填充),默认的模型绑定几个问题,发现我的UI并不完全符合我的模型(如时间域格式化HH:MM是不与时间跨度相匹配)。因此,我想看看创建一个自定义模型绑定是否是一个更好的解决方案。我已经找到了几个例子:<一href=\"http://davidhayden.com/blog/dave/archive/2008/09/08/CustomModelBinderMoreUIValidationASPNETMVC.aspx\">here和<一个href=\"http://www.hanselman.com/blog/SplittingDateTimeUnitTestingASPNETMVCCustomModelBinders.aspx\">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.

我的主要问题是,我不完全理解的ControllerContext和ModelBindingContext的BindModel方法实际上是的,即它们如何与控制器和型号。

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.

如果有人点我的教程或可以看看在<一我将不胜感激href=\"http://davidhayden.com/blog/dave/archive/2008/09/08/CustomModelBinderMoreUIValidationASPNETMVC.aspx\">dave的海登职位和教我怎么可能看起来与目前的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:

<一个href=\"http://odeto$c$c.com/Blogs/scott/archive/2009/04/27/12788.aspx\">http://odeto$c$c.com/Blogs/scott/archive/2009/04/27/12788.aspx

<一个href=\"http://odeto$c$c.com/Blogs/scott/archive/2009/05/05/12801.aspx\">http://odeto$c$c.com/Blogs/scott/archive/2009/05/05/12801.aspx

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

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