PartialViews上的输出缓存不起作用

时间:2011-08-18 00:54:01

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

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

我在其中一个偏好视图中添加了属性,并对其进行了调试。我不断触及方法内的断点(我认为输出缓存不起作用)。我尝试提供参数,cacheprofiles,enableoutputcaching和片段,但效果相同。还有其他我不想要的东西吗?

[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");
        }

是否因为现有的动作过滤器? ValidateInputAttribute?我的PartialView()?

提前致谢。

更新

以下是主视图中有关如何声明partialview的代码段。

        <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组合框。它使用对控制器操作的回调来根据所选值获取数据。我试图看看我是否可以缓存回调的结果。感谢。

1 个答案:

答案 0 :(得分:2)

你怎么称呼它?使用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。简介不会工作。

相关问题