diff --git a/src/Umbraco.Web/Mvc/ActionExecutedEventArgs.cs b/src/Umbraco.Web/Mvc/ActionExecutedEventArgs.cs new file mode 100644 index 0000000000..f0c4f2f620 --- /dev/null +++ b/src/Umbraco.Web/Mvc/ActionExecutedEventArgs.cs @@ -0,0 +1,16 @@ +using System; + +namespace Umbraco.Web.Mvc +{ + public class ActionExecutedEventArgs : EventArgs + { + public UmbracoController Controller { get; set; } + public object Model { get; set; } + + public ActionExecutedEventArgs(UmbracoController controller, object model) + { + Controller = controller; + Model = model; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Mvc/IRenderMvcController.cs b/src/Umbraco.Web/Mvc/IRenderMvcController.cs index c141943bee..755ccd5854 100644 --- a/src/Umbraco.Web/Mvc/IRenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/IRenderMvcController.cs @@ -1,4 +1,6 @@ +using System.Web.Http.Filters; using System.Web.Mvc; +using System.Windows.Forms; using Umbraco.Web.Models; namespace Umbraco.Web.Mvc diff --git a/src/Umbraco.Web/Mvc/PreRenderViewActionFilterAttribute.cs b/src/Umbraco.Web/Mvc/PreRenderViewActionFilterAttribute.cs new file mode 100644 index 0000000000..fae189f9ba --- /dev/null +++ b/src/Umbraco.Web/Mvc/PreRenderViewActionFilterAttribute.cs @@ -0,0 +1,48 @@ +using System; +using System.Web.Mvc; + +namespace Umbraco.Web.Mvc +{ + public class PreRenderViewActionFilterAttribute : ActionFilterAttribute + { + public override void OnActionExecuted(ActionExecutedContext filterContext) + { + var umbController = filterContext.Controller as UmbracoController; + if (umbController == null) + { + return; + } + + var result = filterContext.Result as ViewResultBase; + if (result == null) + { + return; + } + + var model = result.Model; + if (model == null) + { + return; + } + + var args = new ActionExecutedEventArgs(umbController, model); + OnActionExecuted(args); + + if (args.Model != model) + { + result.ViewData.Model = args.Model; + } + + base.OnActionExecuted(filterContext); + } + + + public static event EventHandler ActionExecuted; + + private static void OnActionExecuted(ActionExecutedEventArgs e) + { + EventHandler handler = ActionExecuted; + if (handler != null) handler(null, e); + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index b11ee8efc3..86bccbe224 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -15,6 +15,7 @@ namespace Umbraco.Web.Mvc /// /// A controller to render front-end requests /// + [PreRenderViewActionFilter] public class RenderMvcController : UmbracoController, IRenderMvcController { diff --git a/src/Umbraco.Web/Mvc/UmbracoController.cs b/src/Umbraco.Web/Mvc/UmbracoController.cs index 99efb77f82..d514b56aa6 100644 --- a/src/Umbraco.Web/Mvc/UmbracoController.cs +++ b/src/Umbraco.Web/Mvc/UmbracoController.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Mvc /// /// Returns the current UmbracoContext /// - protected UmbracoContext UmbracoContext { get; private set; } + public UmbracoContext UmbracoContext { get; private set; } /// /// Returns the current ApplicationContext diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 77ffa4fc42..eab4fbcb60 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -361,6 +361,8 @@ + +