Reset the value of textarea after form submission

Solution 1:

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();

Solution 2:

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.

Solution 3:

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);

Solution 4:

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.