BadRequestObjectResult, writing value of type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails'。net core获取参数验证的错误。找到实体验证的错误 电脑版发表于:2023/7/27 21:36 net core获取参数验证的错误,这样写就可以了: ``` services.Configure<ApiBehaviorOptions>(options => { options.InvalidModelStateResponseFactory = (context) => { //var error = context.ModelState.Select(x => x.Value.Errors?.FirstOrDefault().ErrorMessage).ToList(); var newError = context.ModelState.Where(x => x.Value.Errors.Count > 0) .Select(x => new { Name = x.Key, Message = x.Value.Errors?.FirstOrDefault().ErrorMessage }).ToList(); //return new Microsoft.AspNetCore.Mvc.BadRequestObjectResult($"参数验证不通过:{string.Join("|",error)}"); return new UnprocessableEntityObjectResult($"参数验证不通过:{JsonConvert.SerializeObject(newError)}"); }; }); ```