I have a Create action that takes an entity object and a HttpPostedFileBase image. The image does not belong to the entity model.
I can save the entity object in the database and the file in disk, but I am not sure how to validate these business rules:
- Image is required
- Content type must be “image/png”
- Must not exceed 1MB
A custom validation attribute is one way to go:
and then apply on your model:
The controller might look like this:
and the view: