我是一个为应用程序创建菜单的部分页面。我正在使用 renderaction 调用菜单部分 View 。我想通过这样做将这个部分页面存储在客户端
[OutputCache(Duration=7200, Location =OutputCacheLocation.Client, NoStore= true)]
但我收到以下错误
OutputCacheAttribute for child actions only supports Duration, VaryByCustom, and VaryByParam values. Please do not set CacheProfile, Location, NoStore, SqlDependency, VaryByContentEncoding, or VaryByHeader values for child actions
对此的任何替代
最佳答案
客户端缓存对于 MVC 3 中的部分是不可能的。客户端浏览器只接收 HTML,'部分' 只存在于服务器端。
为什么不使用服务器端缓存?
当您的菜单内容依赖于用户时,您可以将相关的用户信息添加到子操作的参数中。例如:
[OutputCache(Duration=7200, VaryByParam="*")]
public PartialViewResult Menu(int userId)
{
...
}
关于c# - 带有部分页面的客户端的 Outputcache 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6410431/