在ASP.NET MVC2中,我使用OutputCache和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?
}如何让它使用这两个参数来缓存页面?我要输入add the attribute两次吗?或者写"customerId,languageId“作为值??
发布于 2010-08-21 23:33:11
VaryByParam的有效值为以下值之一:
* (星号),它随操作方法的所有参数而变化。none (不区分大小写),它随操作方法的任何参数而变化。在您的例子中,您需要第一个选项:
[OutputCache(Duration = 30, VaryByParam = "*")]
public ActionResult Index(int customerId, int languageId)
{
}然而,如果你有一些你想要改变的参数和一些你不想改变的参数,那么你可以使用第三个选项:
[OutputCache(Duration = 30, VaryByParam = "customerId;languageId")] // foo is omitted
public ActionResult Index(int customerId, int languageId, int foo)
{
}发布于 2019-02-08 17:27:25
还可以使用*包含所有参数
[OutputCache(Duration =9234556,VaryByParam = "*")]https://stackoverflow.com/questions/3538012
复制相似问题