Display the same page after saving

Viewed 34625

I'd like show a form with some field (one in the example), submit it, save and display the same page with a reset of all fields. The probelm when I submit, I go the "Save" action but when I display the view the form is still filled in.

The model :

public class TestingModel
{
    public string FirstName { get; set; }
}

The controller :

    public class ChildController : Controller
{
    public ActionResult Index()
    {
        TestingModel model = new TestingModel();
        return View(model);
    }

    public ActionResult Save(TestingModel model)
    {
         Console.WriteLine(model.FirstName); //OK

        //Save data to DB here ...          

        TestingModel testingModel = new TestingModel() { FirstName = string.Empty };
        return View("Index", testingModel);
    }
}

The view :

@using (Html.BeginForm("Save", "Child",FormMethod.Post))
{
    @Html.TextBoxFor( m => m.FirstName)
   <input type="submit" id="btSave" />
}

When Id debug to the view, in "Immediat window" Model.FirstName = "" but when the page is show I still have the value posted. I tried a ReditrectionToAction("Index") at the end of the Save method but same result.

Do you have an idea ?

Thanks,

3 Answers
Related