I have implemented remote validation on a text property without issue, and the remote validation fires correctly, however I am trying to also add validation for an image upload before the form is submitted. Ideally I would like the file to be validated remotely after selecting the local file. Is there any way to get this working? I cannot see what event actually triggers the remote validation, but I guess it is something that isn't fired in an input element for a file. Any suggestions? Thanks
Have tried the following:
ViewModel:
[Remote(action: "ValidatePhoto", controller: "Photos", ErrorMessage = "Photo width and height must be at least 300 pixels")]
public IFormFile Photo { get; set; }
PhotosController:
public IActionResult ValidatePhoto(IFormFile Photo)
{
if (Validation.MeetsMinimumImageDimensions(Photo))
{
return Json(true);
}
return Json(false);
}
View:
<input id="photoUpload" asp-for="Photo" type="file" accept="image/*" name="Photo" style="display:none" />
<span id="submitError" asp-validation-for="Photo" class="text-danger"></span>