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

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

The xx field is required
One or more validation errors occurred

原因是.net core webapi默认参数为不可空,因此会验证并报错。
.net core提示The xx field is required,One or more validation errors occurred_第1张图片
解决方案:
在项目的.csproj中,修改Nullable为disable即可

<PropertyGroup>
    <Nullable>disable</Nullable>
  </PropertyGroup>

.net core提示The xx field is required,One or more validation errors occurred_第2张图片

你可能感兴趣的:(.netcore)