.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>
相关推荐
csdn_aspnet8 小时前
.NETCore、.NET 7 和 RabbitMQ 的发布-订阅模式
rabbitmq·.netcore·.net7.
爱吃香蕉的阿豪9 小时前
深入理解 .NET Core 中的 IServiceScopeFactory:用法、场景与静态类依赖注入
.netcore
sky-stars1 天前
.NET 泛型编程(泛型类、泛型方法、泛型接口、泛型委托、泛型约束)
c#·.net·.netcore
The Sheep 20231 天前
.NetCoreMVC 开发网页使用sass
.netcore·sass
宝桥南山2 天前
.NET10 - 尝试一下Blazor Web Assembly Standalone App的fingerprint新特性
microsoft·微软·c#·asp.net·.net·.netcore
刚子编程4 天前
ASP.NET Core Blazor 核心功能一:Blazor依赖注入与状态管理指南
开发语言·.netcore·blazor
是萝卜干呀4 天前
Backend - HTTP请求的常用返回类型(asp .net core MVC)
http·c#·.netcore·iactionresult
精神小伙就是猛4 天前
.Net Core基于EasyCore.EventBus实现事件总线
微服务·.netcore
sky-stars6 天前
Visual Studio 2022 安装使用:Entity Framework Core
asp.net·.netcore·visual studio
宝桥南山7 天前
.NET - .NET Aspire的Command-Line和GitHub Copilot
microsoft·微软·c#·asp.net·.net·.netcore