.net core提示The xx field is required,One or more validation errors occurred

访问接口时缺少model中的参数时,会提示:

bash 复制代码
The xx field is required
One or more validation errors occurred

原因是.net core webapi默认参数为不可空,因此会验证并报错。

解决方案:

在项目的.csproj中,修改Nullable为disable即可

bash 复制代码
<PropertyGroup>
    <Nullable>disable</Nullable>
  </PropertyGroup>
相关推荐
老龄程序员21 小时前
基于OpenIddict6.4.0搭建的授权UI管理界面
.netcore
武藤一雄1 天前
C# 关于多线程如何实现需要注意的问题(持续更新)
windows·后端·microsoft·c#·.net·.netcore·死锁
冰茶_2 天前
WPF路由事件:隧道与冒泡机制解析
学习·c#·.net·wpf·.netcore·mvvm
武藤一雄2 天前
C# 关于GC垃圾回收需要注意的问题(持续更新)
后端·微软·c#·.net·.netcore
武藤一雄2 天前
C# 关于应用程序域(AppDomain)需要注意的问题(持续更新)
后端·microsoft·微软·c#·.net·.netcore
csdn_aspnet7 天前
在 ASP.NET Core 中发布 RabbitMQ 消息
rabbitmq·.netcore
csdn_aspnet7 天前
在 ASP.NET Core 中使用(消费) RabbitMQ 消息
rabbitmq·.netcore
csdn_aspnet8 天前
ASP.NET Core 应用程序中的单点登录 (SSO)
.netcore·sso
csdn_aspnet8 天前
使用 RabbitMQ 和 MassTransit 在 .NET Core 中实现强大的微服务:处理订阅者故障和消息恢复
微服务·rabbitmq·.netcore
杨大枫9 天前
Minio数据下载
.netcore