lundi 11 septembre 2017

Original values sometimes remain after edit and reload

MVC5 web app. I have a basic Edit method:

    public ActionResult Edit(int StudentId)
    {
        StudentModel model = repo.GetStudent(StudentId);
        return PartialView("_EditLot", model);
    }

and save the post:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit(StudentModel model)
    {
        repo.UpdateStudent(model);
        return RedirectToAction("Index", "Subject", new { SubjectId = model.StudentId });
    }

So I post the edit, save the data in the repo then direct it back to the Index method so it reloads (index contains the student list for that subject with the edit link in the table for each student).

    public ActionResult Index(int ClassId)
    {
         ClassViewModel model = new ClassDataViewModel()
         {
             StudentList = repo.GetStudents(ClassId)
         };
         return View(model);
    }

I often found the original values were still showing after the save and reload when testing in chrome and IE 10 or higher. I then added this to the Edit method (not the post) and it fixed the issue in chrome:

    [OutputCache(Location = System.Web.UI.OutputCacheLocation.None, NoStore = true)]

... but I am still getting intermittent old values on the Index view in IE, out of 10 tests, 3 times I will have old values in the index list.

Aucun commentaire:

Enregistrer un commentaire