Home > Back-end >  Problem with model binding in file input type
Problem with model binding in file input type

Time:03-31

I'm working on an Asp.Net Core MVC project. In my model, I have an IFormFile property. When I use a simple input tag It works fine, But on using the file input plugin in this URL, It fails to do the model binding on the IFormFile property! Has anyone faced the same problem?

Here is the input tag

<input id="input-b2" name="input-b2" type="file"  data-show-preview="false" asp-for="ImageFile" accept="image/jpeg">

The IFormfile property has annotations of Required, Display, and NotMapped

CodePudding user response:

If you use name attribute, it will override the asp-for generated name. For your scenario, you just need to remove it:

<input id="input-b2" type="file"  data-show-preview="false" asp-for="ImageFile" accept="image/jpeg">
  • Related