From 86e879b28830702f0748bc4747a1c2ddc103f15d Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Mon, 2 Sep 2024 14:36:03 +0800 Subject: [PATCH] =?UTF-8?q?:rocket:=20feat(=E6=96=B0=E5=A2=9E):=20?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E9=AA=8C=E8=AF=81=E6=95=B4=E5=90=88=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/GitCommitMessageStorage.xml | 14 +++++++++++++- Bunny.Common/Filter/ValidateModelStateAttribute.cs | 9 +++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml b/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml index e4fd56a..3b56900 100644 --- a/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml +++ b/.idea/.idea.Bunny.WebApi/.idea/GitCommitMessageStorage.xml @@ -2,7 +2,19 @@ \ No newline at end of file diff --git a/Bunny.Common/Filter/ValidateModelStateAttribute.cs b/Bunny.Common/Filter/ValidateModelStateAttribute.cs index a5fba3d..59e3bd6 100644 --- a/Bunny.Common/Filter/ValidateModelStateAttribute.cs +++ b/Bunny.Common/Filter/ValidateModelStateAttribute.cs @@ -2,7 +2,6 @@ using Bunny.Dao.Model.Result; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.AspNetCore.Mvc.ModelBinding; namespace Bunny.Common.Filter; @@ -16,9 +15,11 @@ public class ValidateModelStateAttribute : ActionFilterAttribute if (actionContext.ModelState.IsValid) return; // 表单验证失败 - var errorMessage = actionContext.ModelState.Values.First().Errors.First().ErrorMessage; - var result = - Result.Error(HttpStatusCode.BadRequest, actionContext.ModelState, errorMessage); + var errorMessage = string.Join(",", actionContext.ModelState.Values + .SelectMany(value => value.Errors) + .Select(value => value.ErrorMessage)); + + var result = Result.Error(HttpStatusCode.BadRequest, errorMessage); // 重新复写返回结果 actionContext.Result = new ObjectResult(result);