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.

1

4 Answers 4

3

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

public ViewResult YourAction(YourModel model) 
{
    .........
    ModelState.Clear();
    return View(model); 
}
Sign up to request clarification or add additional context in comments.

1 Comment

Had the same problem. I think this one is the best answer if you are using ASP MVC
2

Add autocomplete='off' to your input tags:

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

Comments

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.

2 Comments

Hmm.. still. Maybe switching off caching isn't what I want. I want to disable form history.
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.
1

Using following JQuery works:

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

Add it inside $(document).ready()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.