Good resources for model binding in ASP.NET MVC3 with C#?
I would like to know how exactly model binding works in ASP.NET MVC3. Since I am still waiting for my Professional ASP.NET MV开发者_如何学JAVAC3 book and I cannot find anything by googling it, you are my last hope.
I know how to perform binding with simple objects but when it comes to ViewModels, especially with nested List<T>
, I am unable to perform binding.
Thanks
Francesco
UPDATE:
For clarification, I mean Model binding from View to Action Methods, thanks
The question is not completely clear, so I'll address what I think you are asking for help on.
In cases where a View Model entity has a property of List<T>
or some other enumerable, it is not automatically bound to the resulting model instance that is available in the action method marked as HttpPost.
You simply need to to find a place to persist the data, or, simply re-query for it in your Action method and update the posted instance.
The most reliable way I have found involves serializing the data to JSON and putting those values into hidden form fields, but when I do this, my view models no longer have the List property, but rather, the serialized properties.
This dilemma usually forces me to re-evaluate the need for the data to be available on form posts, and in most cases it is because I have tried to reuse a view model across views that have different requirements.
As far as I know there is no changes in model binding have been made in mvc3, so I suppose chapter about model binding from Pro ASP.NET MVC V2 Framework is still valid.
I recommend to use javascript when you have to bind nested lists to action parameter.
精彩评论