I am getting started with Asp.Net MVC. This is in my cshtml:
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "form-horizontal" }))
{
@Html.TextBoxFor(m => m.Username, new { @class = "form-control" })
<input type="submit" value="Submit" />
}
This is my controller:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
return View();
}
[HttpPost]
public ActionResult Index(TestModel testModel)
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
testModel.Username = string.Empty;
return View(testModel);
}
}
As you can see when the form is posted I am clearing the Username
property to empty yet the old value stays as it. What am I missing?