return view with empty model

Posted on

Question :

I do the submit to save, and I want it to return in the same view, but with the empty fields, a new model, so it can be added again

But he always comes back with the data I filled out

My action looks like this:

public ActionResult SalvarNovo(grupoViewModel model)
  if (ModelState.IsValid)
    Grupo entity = new Grupo();
    Mapper.Map(model, entity);

  return View("Novo");

How do I return the fields empty? or direct to that view again?


Answer :

Assuming this SalvarNovo is the action of submit of form you simply redirect the user to the action that generates the view of the form.

return RedirectToAction("nome da action que gera o formulario");


Use RedirectToAction :

return RedirectToAction("Novo");


Leave a Reply

Your email address will not be published. Required fields are marked *