c# - 带有部分页面的客户端的 Outputcache 属性

标签 c# asp.net-mvc asp.net-mvc-3 outputcache

我是一个为应用程序创建菜单的部分页面。我正在使用 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/

相关文章:

c# - 测试覆盖 IsValid 的 ValidationAttribute

c# - 实体对象的使用

asp.net-mvc-3 - 从 Controller 发送电子邮件

c# - 模型从 ASP.NET Web API 中的 URI 绑定(bind)到字典

c# - Xamarin 表格 : ScrollView with KeyBoard

c# - PredicateBuilder 返回所有用户 predicate.Or

c# - 我可以将 C# 中的 Javascript 函数添加到 gmail 电子邮件中吗?

asp.net-mvc - Rotativa/Wkhtmltopdf图像不显示

asp.net-mvc - 同一 View 文件夹中的RenderPartial控件

mysql - Entity Framework 如何将 "Image"添加到数据库