0

I am updating a textbox in my View via jQuery on a button click. Then I submit the form and I redirect to new page from post action method. Now when I do a browser back button the get action method is called and I initialize the model with proper values. But when the view is rendered the textbox which was updated by jQuery shows old value and not the one coming from the model. When I do inspect element then the "value" attribute has correct value from model but in UI the element has old value. Then on post I get the incorrect old value.

enter image description here

Below is the code for my get action method

[HttpGet]
    [OutputCache(Duration = 0, NoStore = true, VaryByParam = "None")]
    public ActionResult SelectSeats()
    {            
        EmployeeModel empModel = new EmployeeModel();
        empModel.Name = "keyur";
        empModel.Age = 30;
        empModel.Address = new AddressModel();
        empModel.Address.City = "Mumbai";
        empModel.Address.PinCode = 400064;
        empModel.Address.CountryCode = "AUD";

        return View(empModel);
    }

This is only happening in Chrome browser and working fine in Edge and IE browser.

keyur sheth
  • 29
  • 1
  • 2
  • Please check - https://stackoverflow.com/questions/2699284/make-page-to-tell-browser-not-to-cache-preserve-input-values?noredirect=1&lq=1 https://stackoverflow.com/questions/8861181/clear-all-fields-in-a-form-upon-going-back-with-browser-back-button – Sandesh Feb 24 '18 at 13:36
  • Thanks, Sandesh. Just saw your comment while I was writing my answer. Link you provided does explain and solve my issue. – keyur sheth Feb 24 '18 at 13:49

1 Answers1

0

After some more trial and error I wrote

autocomplete="off"

and now it works fine for Chrome browser. Then I removed the "OutputCache" attribute from my method but it stopped working on IE browser (Edge, Chrome and Firefox were still working).
This shows that in my case I need both the solutions to make it work on all browsers.

keyur sheth
  • 29
  • 1
  • 2