【问题标题】:Output caching on PartialViews doesn't workPartialViews 上的输出缓存不起作用
【发布时间】:2013-01-21 19:01:25
【问题描述】:

主控制器操作上的输出缓存似乎工作正常,但对于 PartialViews,它们似乎没有按预期工作。

我在其中一个部分视图中添加了该属性,并对其进行了调试。我不断地在方法内部打断点(我认为这意味着输出缓存不起作用)。我尝试提供参数、缓存配置文件、启用输出缓存和片段,但效果相同。我还有什么遗漏的吗?

[ValidateInput(false)]
        [OutputCache(Duration = 60000, VaryByParam = "componentId;")]
        public PartialViewResult NewCategoryComboPartial(string componentId)
        {
            //ComponentId
            ViewData[ControllerEnums.GlobalViewDataProperty.ComponentId.ToString()] = componentId;

            //ViewModel
            ViewData[ControllerEnums.GlobalViewDataProperty.ProfileComponentCategories.ToString()] = GetComponentCategoriesList();

            return PartialView("~/Views/Compliance/Profile/Partials/NewCategoryCombo.ascx");
        }

是因为现有的操作过滤器吗?验证输入属性?我的部分视图()?

提前致谢。

更新:

以下是主视图中关于如何声明部分视图的代码 sn-p。

        <div id="compliance-navigation-control">
            <% Html.RenderPartial("~/Views/Shared/Compliance/ComplianceNavigationControl.ascx", Model.PandCRecord); %>
        </div>

下面是部分视图的内容

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="atp.webnav.Web.Controllers" %>
<%@ Import Namespace="atp.webnav.Web.Utilities" %>

<% Html.DevExpress().ComboBox(x =>
        {
            x.Name = "categoryComboBox_" + ViewData[ControllerEnums.GlobalViewDataProperty.ComponentId.ToString()].ToString();  
            x.Theme = "Glass";
            x.Width = Unit.Percentage(100);
            x.Properties.ValueType = typeof(string);
            x.Properties.TextField = "Name";
            x.Properties.ValueField = "Id";
            x.SelectedIndex = 0;
            x.Properties.DropDownStyle = DropDownStyle.DropDown;
            x.Properties.MaxLength = 30;
            x.Properties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
            x.Properties.AllowUserInput = true;
            x.CallbackRouteValues = new {Controller = "Profile", Action = "NewCategoryComboPartial"};
            x.Properties.EnableCallbackMode = true;
            x.Properties.CallbackPageSize = 1000;
            x.Properties.ClientSideEvents.BeginCallback = "webnav.compliance.profile.categoryComboBox_OnBeginCallback";
            x.Properties.ClientSideEvents.SelectedIndexChanged = "webnav.compliance.profile.categoryComboBox_OnSelectedIndexChanged"; 
            x.Properties.ClientSideEvents.EndCallback = "webnav.compliance.profile.categoryComboBox_OnSelectedIndexChanged"; 
            x.Properties.ClientSideEvents.CallbackError = DevExpressGridViewHelper.HandleCallbackErrors;

            x.Properties.EnableSynchronizationOnPerformCallback = true;
        })
        .BindList(ViewData[ControllerEnums.GlobalViewDataProperty.ProfileComponentCategories.ToString()])
        .Render();     
%>

本质上,这个组合框是一个具有自动完成功能的 devexpress 组合框。它使用对控制器操作的回调来根据所选值获取数据。我正在尝试查看是否可以缓存回调的结果。谢谢。

【问题讨论】:

  • 我不确定这是否是您的问题的原因,但您可能需要去掉 VaryByParam 中 componentId 之后的分号
  • 同意——我想就是这样。 PartialViews 上的输出缓存确实 工作(我到处都使用它)。是的,@llapinski 的观点也是有效的。
  • bwisitero 说他设置了被击中的断点,所以我想我的回答可能无效。只是一个猜测 - 也许你直接从页面调用 action 方法,例如你使用 T4MVC 和带有参数 ActionResult 的 Action 方法并且没有重新生成模板?

标签: asp.net-mvc asp.net-mvc-3 outputcache


【解决方案1】:

你怎么称呼它?使用Html.PartialHtml.Action(作为子操作)?

引用Donut Hole Caching in ASP.NET MVC

“Html.RenderPartial 方法忽略视图用户控件上的任何 OutputCache 指令” 所以使用 Html.Action/Html.RenderAction。正如他们在这里所说的Caching ChildActions using cache profiles won't work 使用参数Duraction 和可选的VaryByParam。配置文件不起作用。

【讨论】:

  • 我使用 RenderPartial 来调用它。我将编辑我的帖子以包含调用页面以使其更清晰。
猜你喜欢
  • 1970-01-01
  • 2011-10-27
  • 2012-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多