ASP.Net MVC Custom Model Binding explanation

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

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 (eg 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.

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

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/archive/2009/04/27/12788.aspx

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


Here's a good explanation of ModelBinders that I believe will cover your questions: http://www.singingeels.com/Articles/Model_Binders_in_ASPNET_MVC.aspx

A quick Google search pulled up a few others... I will let you filter through them :-)

链接地址: http://www.djcxy.com/p/60436.html

上一篇: Html.HiddenFor做什么?

下一篇: ASP.Net MVC自定义模型绑定说明