如何将VaryByParam与多个参数一起使用?


103

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

如何使用两个参数来缓存页面?是否输入两次添加属性?还是写“ customerId,languageId”作为值?

Answers:



1

您还可以*用来包含所有参数

 [OutputCache(Duration =9234556,VaryByParam = "*")]

1
欢迎使用堆栈溢出。尽管此代码可以回答问题,但提供有关此代码为何和/或如何回答问题的其他上下文,可以改善其长期价值。如何回答
Elletlar '19
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.