Jonny Nabors
Jonny Nabors

Reputation: 310

Pass Model to controller using Html.HiddenFor

At form submission, I am using @Html.HiddenFor(a => a.ModelParameter) to hold all of the values as it makes its way to the controller. My question is, for Models that have many parameters (25+) is there a better way to pass all of those parameters using @Html.HiddenFor?

For example,

foreach(var parameter in Model) { @Html.HiddenFor(modelItem => modelItem.parameter) }

Or something along these lines to avoid having to do an individual @Html.HiddenFor for every single parameter.

Upvotes: 2

Views: 1743

Answers (1)

muddymess
muddymess

Reputation: 303

You could set an attribute on the properties that are supposed to be hidden.

Is there some way to use @Html.HiddenFor for complete model?

Upvotes: 1

Related Questions