【发布时间】: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