Reset the value of textarea after form submission

The problem is the HtmlHelper is retrieving the ModelState value, which is filled with the posted data. Rather than hacking round this by resetting the ModelState, why not redirect back to the [get] action. The [post] action could also set a temporary status message like this:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Message(int ID, string SomeText)
{
  // save Text to database
  SaveToDB(ID, SomeText);

  TempData["message"] = "Message sent";
  return RedirectToAction("Message");
}

This seems to me like more correct behaviour.


The html helpers read the value from the ModelState. And there's no elegant way to override this behaviour.

But if you add this line after SaveToDB(ID, SomeText), it should work :

ModelState["SomeText"].Value = 
    new ValueProviderResult("", "", CultureInfo.CurrentCulture);

The problem is that your ModelState is re-filled with the posted values.

What you can do is clear it on the Action that has the Post attribute :

ModelState.Clear();

I tried everything, but only worked when I did something like this:

ModelState.Clear();
//This will clear the address that was submited
viewModel.Address = new Address();
viewModel.Message = "Dados salvos com sucesso!";
return View("Addresses", ReturnViewModel(viewModel));

Hope this helps.