Pass an entire model on form submission

jpo picture jpo · Mar 20, 2013 · Viewed 43.5k times · Source

I understand that I can use @Html.HiddenFor(m => m.parameter) and when the form is submitted, that parameter will be passed to the controller. My model has many properties.

Is there a shorter way of passing the entire model at once to the controller or must I do it one by one each time?

Answer

Forty-Two picture Forty-Two · Mar 20, 2013

The model will be passed to the controller in its entirety, but the values of properties that are not bound by input or hidden fields will be lost.

You have to either bind the properties in the form on the client-side, or re-fetch the entity on the server-side.

You seem to be asking for something like @Html.HiddenFor(m => m.Model), and that is not possible. Sorry

One thing to keep in mind, if you have tons of hidden fields, you may be sending more data to the view than you really need. Consider employing view models