Hi please take a look at this code:
// if the image url doesn't contain a valid image
if (!ArticleToCreate.image.Contains(".jpg")
|| !ArticleToCreate.image.Contains(".jpeg")
|| !ArticleToCreate.image.Contains(".png")
|| !ArticleToCreate.image.Contains(".gif")
|| !ArticleToCreate.image.Contains(".bmp"))
{
ModelState.AddModelError("Image", "Please enter a valid URL.");
}
Why wouldn’t this work? The plan is to basically say if the value of image doesn’t have one of those extensions then error. It looks fine to me but doesn’t work. If I have ‘MyImage.png’ it should allow it but not ‘MyImage.hhh’ but it doesn’t allow anything. Why? Thanks
It is because your Image path should have all the extensions as per your logic. change it to:
To have least number of extensions checks use this version: