开发者

Can I bind multiple forms to a single model using the default model binder?

I have a complex page with several forms on it. The page is divided into sections, and each section has a continue button on it.

The page is bound to a pageViewModel, each section addresses a different set of properties on the model.

The continue but开发者_JAVA技巧ton makes an ajax call to the controller, and the model binder binds it appropriately to the appropriate sections of the model. The section is refreshed appropriately.

Finally, I would like to have a save button at the bottom of the page that takes all the forms, and binds all of the forms to the model. The model, at this point has all of the properties filled out, and can be processed accordingly.

Can I accomplish this by some ASP MVC magic?


ASP.NET MVC Futures contains nice helper method that allows you to serialize the model into a hidden field that can be fetched in the next controller action that the form is being posted to. This allows a WebForms ViewState imitation.


I would do it the other way round: For the sections use jquery to only submit the elements of the section. You already use ajax here. It might not be a big deal to filter the elements to post.

This way the save action would not require extra work.

You are also able to have ths working without javascript. It needs more work for the continue actions, but at least its posssible. There is no chance to get this working without javascript with multiple forms for the save action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜