.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>
相关推荐
驾驭人生5 小时前
Asp .Net Core 系列:Asp .Net Core 集成 Hangfire+MySQL
数据库·mysql·.netcore
时光追逐者5 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 53 期(2025年9.1-9.7)
c#·.net·.netcore
somethingGoWay1 天前
wpf .netcore 导出docx文件
wpf·.netcore
somethingGoWay1 天前
wpf .netcore 导出pdf文件
pdf·wpf·.netcore
切糕师学AI2 天前
如何建立针对 .NET Core web 程序的线程池的长期监控
java·前端·.netcore
csdn_aspnet3 天前
使用 MongoDB.Driver 在 C# .NETCore 中实现 Mongo DB 过滤器
mongodb·c#·.netcore
tiancao2223 天前
安装3DS MAX 2026后,无法运行,提示缺少.net core的解决方案
.net·.netcore·3dsmax
csdn_aspnet3 天前
使用 C# .NETCore 实现MongoDB
mongodb·c#·.netcore
MoFe17 天前
【.net core】【NPOI】读取表格信息(处理合并行表格数据)
.netcore
csdn_aspnet7 天前
在 .NET Core 中实现基于策略和基于角色的授权
.netcore·role·policy