.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>
相关推荐
爱吃香蕉的阿豪13 小时前
SignalR 全解析:核心原理、适用场景与 Vue + .NET Core 实战
vue.js·microsoft·c#·.netcore·signalr
工藤新一OL2 天前
把xml的格式从utf-8-bom转为utf-8
xml·c#·asp.net·.netcore·visual studio
王柏龙2 天前
Asp.net core mvc中TagHelper的GetChildContentAsync和Content区别
mvc·.netcore
编程乐趣4 天前
基于.Net Core开源的库存订单管理系统
.netcore
lgaof65822@gmail.com7 天前
ASP.NET Core Web API 中集成 DeveloperSharp.RabbitMQ
后端·rabbitmq·asp.net·.netcore
爱吃香蕉的阿豪7 天前
在.NET Core API 微服务中使用 gRPC:从通信模式到场景选型
微服务·.netcore·信息与通信·grpc
孤的心了不冷8 天前
【后端】.NET Core API框架搭建(7) --配置使用Redis
数据库·redis·缓存·.netcore
孤的心了不冷9 天前
【后端】Linux系统发布.NetCore项目
.netcore
csdn_aspnet9 天前
在 .NET Core 中创建 Web Socket API
javascript·websocket·.netcore