You can create an extensions method, something like this:
public static string? AltText(this MediaWithCrops? media)
{
if (media?.Content is not Image image)
{
return null;
}
return string.IsNullOrWhiteSpace(image.UmbracoAltText)
? image.Name
: image.UmbracoAltText;
}
Then just call:
@Model.MyImageProperty.AltText()
Justin