Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBoxFor value not updating after post

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?

like image 833
broke Avatar asked Aug 27 '13 16:08

broke


1 Answers

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);
}
like image 182
Satpal Avatar answered Oct 22 '22 05:10

Satpal