ASP.Net MVC 2: how to store values ​​in a model between posts

I have an edit view that displays some of the model properties as plain text and other model properties as input fields. My problem is that the properties of the model displayed as plain text are null when the model is returned to the view after a validation error.

How can I store model values ​​if I don't have input fields for all properties? What practice?

My first thought is to store the values ​​of these properties in hidden input elements.

<%= Html.HiddenFor(model => model.CustomerName) %>

      

Is this the right solution?

Thanks Andreas

+2


a source to share


1 answer


You can:

  • Use hidden fields as you suggest, or
  • Re-fill the "missing" fields before returning the view to action POST

    .


Choose what works for your application.

+5


a source







All Articles