如何使用VaryByParam时有多个参数?

问题描述 投票:99回答:2

在ASP.NET MVC2我用OutputCacheVaryByParam属性。我得到它的工作罚款与一个单一的参数,但什么是我对法的几个参数的正确语法?

[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?
}

我如何得到它使用缓存两个参数的页面?难道我进入添加属性两次?或者写“客户ID,languageId”的价值?

asp.net-mvc-2 outputcache
2个回答
190
投票

您可以使用*对所有参数或分号分隔列表(VaryByParam = "customerId;languageId")。

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

Here's a nice write up specifically for MVC


0
投票

您还可以使用*包括所有参数

 [OutputCache(Duration =9234556,VaryByParam = "*")]
© www.soinside.com 2019 - 2024. All rights reserved.