2010-08-21 20 views
85

在ASP.NET MVC2中,我使用OutputCacheVaryByParam屬性。我用一個參數就可以正常工作,但當我在該方法上有幾個參數時,正確的語法是什麼?如何在多個參數中使用VaryByParam?

[OutputCache(Duration=30, VaryByParam = "customerId"] 
public ActionResult Index(int customerId) 
{ 
//I've got this one under control, since it only has one parameter 
} 

[OutputCache(Duration=30, VaryByParam = "customerId"] 
public ActionResult Index(int customerId, int languageId) 
{ 
//What is the correct syntax for VaryByParam now that I have a second parameter? 
} 

如何使用兩個參數來緩存頁面?我輸入兩次添加屬性嗎?或者寫下「customerId,languageId」作爲值?

回答

171

您可以將*用於所有參數或分號分隔列表(VaryByParam = "customerId;languageId")。

您也可以使用沒有,如果你不希望它緩存不同版本....

Here's a nice write up specifically for MVC

+0

鏈接不起作用 – Espo 2011-09-13 08:36:22

+1

更新了鏈接。 :-) – klabranche 2011-11-02 17:17:52

相關問題