在asp.net MVC3中关闭表单缓存

时间:2012-05-23 12:50:59

标签: asp.net asp.net-mvc asp.net-mvc-3

我正在尝试关闭MVC3中的页面缓存。试过了:

@{
    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 "); 
 }

但是没有奏效。感谢。


刚才意识到我可能会问错误的事情。我想禁用表单历史记录,以便在填充表单字段时不显示选项先前的值。

4 个答案:

答案 0 :(得分:3)

使用ModelState.Clear();在你的行动中清除模型状态:

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

答案 1 :(得分:2)

autocomplete='off'添加到输入标记:

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

答案 2 :(得分:1)

尝试将此添加到控制器内的操作

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

我有类似的问题,应该可以解决这个问题。

答案 3 :(得分:1)

使用以下JQuery工作:

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

$(document).ready()

中添加
相关问题