0

When a user posts a form to register, if ModelState is not valid, I would like to have the input form values placed back into the appropriate form fields so they do not have to fill out the entire form again. I could pass back the object to the view and then set the value field on each form input. Is this the only way to do it.

Thanks

Dietpixel
  • 9,983
  • 11
  • 28
  • 33
  • 2
    This should happen automagically. Can you post your view and controller? – Iain Galloway Aug 27 '11 at 21:42
  • Ah, I didn't realize you HAD to use the html helpers for this to work. How can I add an Id to a html helper? @Html.TextBox("username") – Dietpixel Aug 27 '11 at 22:02
  • One of the overloads takes an anonymous type for html attributes. @Html.TextBox("username", new { id = "whatever" }) if I recall correctly. – Iain Galloway Aug 27 '11 at 22:05

1 Answers1

3

The HTML helpers by default exhibit this behavior. How are you coding this? Html.TextBoxFor does this for example. The helpers use the posted values when you are in a post action and render a view without redirecting.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71