开发者

Output caching on PartialViews doesn't work

开发者 https://www.devze.com 2023-03-29 09:36 出处:网络
OutputCaching on the main controller actions seems to work fine but for PartialViews they don\'t seem to work as expected.

OutputCaching on the main controller actions seems to work fine but for PartialViews they don't seem to work as expected.

I added the attribute in one of the partialviews, debugged it. I continuously hit the breakpoint inside the method (which i think means output caching isn't working). I tried providing parameters, cacheprofiles, enablingoutputcaching and fragments but same effect. Is there something else that I am missing?

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

Is it because of an existing action filter? ValidateInputAttribute? My PartialView()?

Thanks in advance.

UPDATE:

Below is the code snippet from the main view on how the partialview is declared.

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

Below is the content of the partialview

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

<% Html.Dev开发者_开发问答Express().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();     
%>

Essentially this combobox is a devexpress combobox that has autocomplete features. It uses callbacks to the controller actions to get the data based on the value selected. I am trying to see if I can cache the results of the callback. Thanks.


How are you calling it? Using Html.Partial or Html.Action (as a child action)?

Quoting from Donut Hole Caching in ASP.NET MVC

"the Html.RenderPartial method ignores any OutputCache directives on the view user control" so use Html.Action/Html.RenderAction. As they say here Caching ChildActions using cache profiles won't work use parameters Duraction and optionally VaryByParam. Profile wont work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号