简体   繁体   中英

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 button 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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM