Bit.Api.Utilities.ModelStateValidationFilterAttribute.OnActionExecuting C# (CSharp) Метод

OnActionExecuting() публичный Метод

public OnActionExecuting ( Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext context ) : void
context Microsoft.AspNetCore.Mvc.Filters.ActionExecutingContext
Результат void
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var model = context.ActionArguments.FirstOrDefault(a => a.Key == "model");
            if(model.Key == "model" && model.Value == null)
            {
                context.ModelState.AddModelError(string.Empty, "Body is empty.");
            }

            if(!context.ModelState.IsValid)
            {
                context.Result = new BadRequestObjectResult(new ErrorResponseModel(context.ModelState));
            }
        }
ModelStateValidationFilterAttribute