stats101
stats101

Reputation: 1877

Switch off form caching in asp .NET MVC3

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.

Upvotes: 1

Views: 1970

Answers (4)

stats101
stats101

Reputation: 1877

Using following JQuery works:

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

Add it inside $(document).ready()

Upvotes: 1

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

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

public ViewResult YourAction(YourModel model) 
{
    .........
    ModelState.Clear();
    return View(model); 
}

Upvotes: 3

Richard
Richard

Reputation: 30618

Add autocomplete='off' to your input tags:

<input type="text" autocomplete="off" ... />

Upvotes: 2

Henry
Henry

Reputation: 2187

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.

Upvotes: 1

Related Questions