我正在使用ASP.NET Core MVC,并希望通过验证属性来验证模型中的IFormFile属性。
我的模特:
[Required(ErrorMessage = "Please upload an book image")]
public IFormFile BookImage { get; set; }
我的cshtml文件:
<input asp-for="BookImage" type="file" accept="image/*"/>
<span asp-validation-for="BookImage" class="text-danger"></span>
但是当不选择文件并按提交按钮时,表单仍然可以提交。它不需要BookImage。
为什么?以及如何使IFormFile成为必需?谢谢。