var image = Umbraco.Media(Umbraco.Field("myImage").ToString());
var lang = "en";
var fieldValue = image.GetPropertyValue<string>($"alt_{lang}");
I have the above code. I see that image is of type dynamic. But with dynamics I'm never sure whether a property or method exists. Is there a more strongly typed/better way of doing the above?
Better way to check for Field value on an image
I have the above code. I see that image is of type dynamic. But with dynamics I'm never sure whether a property or method exists. Is there a more strongly typed/better way of doing the above?
Ultimately I'd like to:
Hi Sebastian,
To get a strongly typed media object change your first line of code to this :
Dave
Hi fives - thanks Dave
But if you really like to work with strongly typed models you can have a look at ModelsBuilder
I wrote a article that should get you started ; https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/
Dave
is working on a reply...