1

I'm trying to switch off page caching in MVC3. Have tried:

@{
    Response.AddHeader("Cache-Control","no-cache");
    Response.AddHeader("Pragma", "no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0 "); 
 }

But hasn't worked. Thanks.


Just realised I may be asking for the wrong thing. I want to disable form history such that options previous values are not shown when populating a form field.

stats101
  • 1,837
  • 9
  • 32
  • 50

4 Answers4

3

Use ModelState.Clear(); in your action to clear model state:

public ViewResult YourAction(YourModel model) 
{
    .........
    ModelState.Clear();
    return View(model); 
}
Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52
2

Add autocomplete='off' to your input tags:

<input type="text" autocomplete="off" ... />
Richard
  • 29,854
  • 11
  • 77
  • 120
1

Try adding this to your action inside the controller

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult Test() {
 ...
}

Ive had similar issues, that should do the trick.

Henry
  • 2,187
  • 1
  • 15
  • 28
  • Hmm.. still. Maybe switching off caching isn't what I want. I want to disable form history. – stats101 May 23 '12 at 13:55
  • What chain of events cause it to show previous values? If you dont pass in a model or a null model then all text box's should be empty. – Henry May 23 '12 at 14:08
1

Using following JQuery works:

$(':text').attr("autocomplete", "off");

Add it inside $(document).ready()

tghw
  • 25,208
  • 13
  • 70
  • 96
stats101
  • 1,837
  • 9
  • 32
  • 50