From 37bf6fe9385f026f6921ea03330e2ded57914fa6 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 3 Jul 2019 19:15:54 +1000 Subject: [PATCH] Automatically refresh the page if we encounter a ModelBindingException --- .../Mvc/ModelBindingExceptionFilter.cs | 23 +++++++++++++++++++ src/Umbraco.Web/Mvc/RenderMvcController.cs | 2 ++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 3 files changed, 26 insertions(+) create mode 100644 src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs diff --git a/src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs b/src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs new file mode 100644 index 0000000000..714a916e6a --- /dev/null +++ b/src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs @@ -0,0 +1,23 @@ +using System.Web.Mvc; + +namespace Umbraco.Web.Mvc +{ + /// + /// An exception filter checking if we get a in which case it returns the html to auto refresh the page + /// + internal class ModelBindingExceptionFilter : FilterAttribute, IExceptionFilter + { + public void OnException(ExceptionContext filterContext) + { + if (!filterContext.ExceptionHandled && filterContext.Exception is ModelBindingException) + { + filterContext.Result = new ContentResult + { + Content = "

Loading page...

", + ContentType = "text/html" + }; + filterContext.ExceptionHandled = true; + } + } + } +} diff --git a/src/Umbraco.Web/Mvc/RenderMvcController.cs b/src/Umbraco.Web/Mvc/RenderMvcController.cs index c2aa3bd8ed..64c9ad52c4 100644 --- a/src/Umbraco.Web/Mvc/RenderMvcController.cs +++ b/src/Umbraco.Web/Mvc/RenderMvcController.cs @@ -10,10 +10,12 @@ using Umbraco.Web.Routing; namespace Umbraco.Web.Mvc { + /// /// Represents the default front-end rendering controller. /// [PreRenderViewActionFilter] + [ModelBindingExceptionFilter] public class RenderMvcController : UmbracoController, IRenderMvcController { private PublishedRequest _publishedRequest; diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index c9cbc46a35..b6b7bc5599 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -218,6 +218,7 @@ +