ASP.NET MVC 2 控制器未缓存
我有一个调用渲染操作的母版页:
<% Html.RenderAction("CategoryList", "Category", new { selectedCategoryId = Model.selectedCategoryId }); %>
操作看起来像:
[ChildActionOnly]
[OutputCache(Duration = 10, VaryByParam = "none")]
public ActionResult CategoryList(int? selectedCategoryId)
{
CategoryList cl = CategoryManager.GetList();
if (selectedCategoryId.HasValue)
CategoryManager.SetSelectedCategory(cl, selectedCategoryId.Value);
return PartialView(cl);
}
但是当我运行 SQL 探查器时,我看到 GetList() 查询始终被调用,这意味着该操作没有被缓存。
知道我做错了什么吗?
谢谢!
I have amaster page that calls render action:
<% Html.RenderAction("CategoryList", "Category", new { selectedCategoryId = Model.selectedCategoryId }); %>
and the action looks like:
[ChildActionOnly]
[OutputCache(Duration = 10, VaryByParam = "none")]
public ActionResult CategoryList(int? selectedCategoryId)
{
CategoryList cl = CategoryManager.GetList();
if (selectedCategoryId.HasValue)
CategoryManager.SetSelectedCategory(cl, selectedCategoryId.Value);
return PartialView(cl);
}
But when i run SQL profiler i see that the GetList() query is always called, meaning the action is not being cached.
Any idea what i'm doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是一个子操作,意味着它只是最终 HTML 的一部分,无法缓存。用于缓存 HTML 结帐片段此博客文章。
It's a child action meaning that it is only a part of the final HTML and cannot be cached. For caching fragments of your HTML checkout this blog post.
很简单,使用OutputCacheAttribute。
保重,拉吉姆斯
its easy, use OutputCacheAttribute.
Take care, Ragims