.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>
相关推荐
[email protected]3 小时前
ASP.NET Core自动事务ActionFilter
后端·asp.net·.netcore
刘梦凡呀3 天前
C# .NET Core 批量下载文件
windows·c#·.netcore
Zhen (Evan) Wang3 天前
.NET 6 WPF 利用CefSharp.Wpf.NETCore显示PDF文件
.net·wpf·.netcore
时光追逐者4 天前
C#/.NET/.NET Core拾遗补漏合集(25年4月更新)
c#·.net·.netcore
追雨潮4 天前
.net core 项目快速接入Coze智能体-开箱即用-第2节
.netcore
追雨潮5 天前
.net core 项目快速接入Coze智能体-开箱即用-全局说明
.netcore·ai编程
时光追逐者5 天前
C#/.NET/.NET Core技术前沿周刊 | 第 35 期(2025年4.14-4.20)
c#·.net·.netcore
全栈小55 天前
【C#】.net core 6.0调用MVC API接口时,提示Unsupported Media Type,状态码415
c#·mvc·.netcore
猫霸6 天前
理解.NET Core中的配置Configuration
html·.netcore·xhtml
MoFe16 天前
【.net core】【watercloud】数据库连接报错问题
数据库·.netcore