C# – TextBoxFor value not updating after post

asp.net-mvcasp.net-mvc-4c

I have a simple strongly typed view, but I cant seem to update a textbox on my form after a post.

Here is my model:

public class Repair
  {
    public string Number { get; set; }      
  }

And in my view is a TextBox:

   @Html.TextBoxFor(x => x.Number)

I'm trying to update the textbox after a post to my controller:

 [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(Repair r)
        {

          r.Number = "New Value";

          return View(r);

        }

Even though I'm setting Number to a new value, the text in the textbox does not change. What am I doing wrong?

Best Answer

Use ModelState.Clear() before setting value

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(Repair r)
{
    ModelState.Clear(); //Added here
    r.Number = "New Value";
    return View(r);
}