Automatically refresh the page if we encounter a ModelBindingException
This commit is contained in:
23
src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs
Normal file
23
src/Umbraco.Web/Mvc/ModelBindingExceptionFilter.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// An exception filter checking if we get a <see cref="ModelBindingException"/> in which case it returns the html to auto refresh the page
|
||||
/// </summary>
|
||||
internal class ModelBindingExceptionFilter : FilterAttribute, IExceptionFilter
|
||||
{
|
||||
public void OnException(ExceptionContext filterContext)
|
||||
{
|
||||
if (!filterContext.ExceptionHandled && filterContext.Exception is ModelBindingException)
|
||||
{
|
||||
filterContext.Result = new ContentResult
|
||||
{
|
||||
Content = "<html><head><meta http-equiv=\"refresh\" content=\"3\" /></head><body><p>Loading page...</p></body></html>",
|
||||
ContentType = "text/html"
|
||||
};
|
||||
filterContext.ExceptionHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,12 @@ using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Represents the default front-end rendering controller.
|
||||
/// </summary>
|
||||
[PreRenderViewActionFilter]
|
||||
[ModelBindingExceptionFilter]
|
||||
public class RenderMvcController : UmbracoController, IRenderMvcController
|
||||
{
|
||||
private PublishedRequest _publishedRequest;
|
||||
|
||||
@@ -218,6 +218,7 @@
|
||||
<Compile Include="Models\Mapping\MapperContextExtensions.cs" />
|
||||
<Compile Include="Models\PublishedContent\HybridVariationContextAccessor.cs" />
|
||||
<Compile Include="Models\TemplateQuery\QueryConditionExtensions.cs" />
|
||||
<Compile Include="Mvc\ModelBindingExceptionFilter.cs" />
|
||||
<Compile Include="Mvc\SurfaceControllerTypeCollectionBuilder.cs" />
|
||||
<Compile Include="Profiling\WebProfilingController.cs" />
|
||||
<Compile Include="PublishedCache\NuCache\Snap\GenObj.cs" />
|
||||
|
||||
Reference in New Issue
Block a user