2012-05-23 50 views
1

我想關閉頁面緩存在MVC3。已嘗試:關閉窗體緩存在asp.net中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 "); 
} 

但沒有奏效。謝謝。


剛剛意識到我可能會問錯的東西。我想禁用表單歷史記錄,以便在填充表單字段時不顯示選項先前的值。

+0

http://stackoverflow.com/questions/1160105/asp-net-mvc-disable-browser-cache –

回答

2

添加autocomplete='off'您輸入標籤:

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

嘗試添加該到你的動作控制器

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

Ive有類似的問題,是應該做的伎倆內。

+0

嗯..依然。也許關閉緩存並不是我想要的。我想禁用表單歷史記錄。 – stats101

+0

什麼樣的事件導致它顯示以前的值?如果你不傳入模型或空模型,那麼所有的文本框應該是空的。 – Henry

1

使用以下jQuery的原理:

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

添加這裏面$(document).ready()

+0

此解決方案不起作用 – BrainCoder

3

使用ModelState.Clear();在你的行動,明確模型狀態:

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

有同樣的問題。我認爲這是一個最好的答案,如果你使用ASP MVC –

+0

工作!真棒MVC 4 – Badulake