ASP.Net MVC 2: How to keep values in the model between posts

Posted by Andreas on Stack Overflow See other posts from Stack Overflow or by Andreas
Published on 2010-04-29T13:15:04Z Indexed on 2010/04/29 13:17 UTC
Read the original article Hit count: 496

Filed under:

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

How do I retain the model values when I don't have input fields for all properties? What is best practice?

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

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

Is this considered a correct solution?

Thanks Andreas

© Stack Overflow or respective owner

Related posts about asp.net-mvc