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,727
  • 7
  • 30
  • 49

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,352
  • 1
  • 40
  • 50
2

Add autocomplete='off' to your input tags:

<input type="text" autocomplete="off" ... />
Richard
  • 27,531
  • 8
  • 67
  • 116
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
  • 27
  • 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
  • 24,294
  • 13
  • 66
  • 95
stats101
  • 1,727
  • 7
  • 30
  • 49