output modelstate errors in case a post body can't be converted

This commit is contained in:
2020-08-13 12:03:24 +02:00
parent afd777f99f
commit 175754894d
8 changed files with 39 additions and 15 deletions
+2 -2
View File
@@ -14,7 +14,7 @@ export default [
},
{
tab: 'meta',
field: 'meta.titleOverride',
field: 'meta.titleOverrideAll',
display: 'text',
label: 'Title override all'
},
@@ -27,7 +27,7 @@ export default [
},
{
tab: 'meta',
field: 'meta.seoImage',
field: 'meta.seoImageId',
display: 'media',
label: 'SEO image'
},
@@ -12,7 +12,7 @@ namespace zero.TestData
public string SeoDescription { get; set; }
public Media SeoImage { get; set; }
public string SeoImageId { get; set; }
public bool NoFollow { get; set; }
@@ -51,7 +51,7 @@
.ui-property + .ui-property
{
padding-top: 30px;
margin-top: 50px;
margin-top: 30px;
border-top: 1px solid var(--color-line-light);
}
+4 -9
View File
@@ -113,7 +113,7 @@
{
display: inline-flex;
align-items: center;
height: 58px;
height: 56px;
overflow: hidden;
padding: 0 var(--padding);
font-size: var(--font-size);
@@ -121,12 +121,7 @@
position: relative;
transition: color 0.2s ease;
border-radius: var(--radius) var(--radius) 0 0;
background: rgba(white, 0.4);
.theme-dark &
{
background: rgba(black, 0.5);
}
background: var(--color-bg-xxlight);
& + .ui-tabs-list-item
{
@@ -177,10 +172,10 @@
background: var(--color-bg);
}
&:before
/*&:before
{
background: var(--color-secondary);
}
}*/
&:after
{
@@ -17,6 +17,7 @@ namespace zero.Web.Controllers
{
[ZeroAuthorize]
[BackofficeGenericController]
[ServiceFilter(typeof(ModelStateValidationFilterAttribute))]
public abstract class BackofficeController : Controller, ISupportsGenericsController
{
IMapper _mapper;
@@ -6,11 +6,16 @@ namespace zero.Web.Filters
{
public class BackofficeGenericControllerAttribute : Attribute, IControllerModelConvention
{
const char BACKTICK = '`';
const string CONTROLLER = "Controller";
public void Apply(ControllerModel controller)
{
if (controller.ControllerName.Contains('`'))
if (controller.ControllerName.Contains(BACKTICK))
{
controller.ControllerName = controller.ControllerName.Split('`')[0].TrimEnd("Controller");
controller.ControllerName = controller.ControllerName.Split(BACKTICK)[0].TrimEnd(CONTROLLER);
}
}
}
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace zero.Web.Filters
{
public class ModelStateValidationFilterAttribute : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
if (!context.ModelState.IsValid)
{
context.Result = new BadRequestObjectResult(context.ModelState);
}
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
}
}
+3
View File
@@ -22,6 +22,7 @@ using zero.Core.Options;
using zero.Core.Plugins;
using zero.Core.Validation;
using zero.Web.Defaults;
using zero.Web.Filters;
namespace zero.Web
{
@@ -100,6 +101,8 @@ namespace zero.Web
Services.AddTransient<IBackofficeStore, BackofficeStore>();
Services.AddTransient(typeof(IAppScope<>), typeof(AppScope<>));
Services.AddScoped<ModelStateValidationFilterAttribute>();
Services.AddHttpContextAccessor();
Services.AddTransient<IZeroVue, ZeroVue>();