Clearing text box fields on a page in MVC

Or if the ModelState was valid you just can Redirect back to Get Action like this:

public ActionResult Index()
{
   return View();
}

[HttpPost]
public ActionResult Index(Person p)
{
  if (ModelState.IsValid)
  {
    // do work and finally back to Get Action
    return RedirectToAction("Index");
  }

  return View(p);
}

Hi you should be able to use: ModelState.Clear() and when you return the View all previous entered data will be cleared.

Edit:

Here's some example code:

public ActionResult Index()
{
  return View();
}

[HttpPost]
public ActionResult Index(FormCollection collection)
{
  // This will clear whatever form items have been populated
  ModelState.Clear();

  return View();
}

Update 2:

In your code you are clearing the ModelState however your passing the Model (you've called it m) back to your view and your view is then picking this model and displaying its properties.

If for example I have a page which accepted a first name and last name and when I post I want to add this to a database but then return the same view but empty for my next request my code would look something like:

public ActionResult Index()
{
  return View();
}

[HttpPost]
public ActionResult Index(Person p)
{
  if (ModelState.IsValid)
  {
    // This will clear whatever form items have been populated
    ModelState.Clear();
    // Here I'm just returning the view I dont want a model being passed
    return View();
  }

  // Here I'm returning the model as there's an error and the user needs to see
  // what has been entered.
  return View(p);
}