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?
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With