It seems as though Asp.Net MVC has given me a number of gotchas lately. I was writing an application allowing users to post in a question like format. MVC would post a form to the same url, and I would update the form with the next question. One issue though: Asp.Net MVC would not update the form with the new question information. Something like this:
Html.TextboxFor(m => m.MyProperty)
On the controller side of things I would update the model:
// save off MyProperty to the database model.MyProperty = “The stuff should change”; return View(model);
The textbox would still contain the original text. Boo! I knew it wasn’t a problem with the variable assignment because the following would reflect any changes I made:
Hours later it dawned on me: Could Asp.Net be saving the form data in the ModelState and disregarding the property with the ModelState? Answer? Yes… *sigh* This fixes this current issue:
I hope this helps someone down the road because it made me cry in a corner.