【发布时间】:2015-11-18 01:47:38
【问题描述】:
我正在开发一个网站框架,该框架使用“小部件”在门户/portlet 类型的网站内呈现内容块。基本上是 Wordpress 如何让您自定义网站的一个非常简略的版本。
搜索并未能找到任何现有框架,似乎最合理的实现方式是使用 MVC 的“部分视图”功能。
我希望能够完全封装每个“小部件”,而不必在宿主视图中重复脚本或样式标签(视图不需要知道如何呈现小部件)。
为了实现这一点,任何脚本引用都由 Widget 部分视图存储,然后在视图呈现自己的脚本部分时注入。在一种情况下,这是使用响应过滤器实现的。
我正在通过 CoreCLR 使用 MVC 6 (vNext),并试图确定如何在新框架下实现此过滤器位。看起来 HttpResponse 对象不再有“过滤器”字段。
你能告诉我这在新框架下如何工作吗?
/// <summary>
/// Appends partial view scripts to the html response of an AJAX request
/// </summary>
public class RenderAjaxPartialScriptsAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
var response = filterContext.HttpContext.Response;
if (response.Filter != null)
response.Filter = new RenderAjaxPartialScriptsResponseFilter(response.Filter, filterContext);
}
}
}
原始代码来自 Ryan Burnham 的博客https://rburnham.wordpress.com/2015/03/13/asp-net-mvc-defining-scripts-in-partial-views/#comment-2286
【问题讨论】:
标签: asp.net-mvc asp.net-core asp.net-core-mvc