Compiler Error Message: CS1061: 'Umbraco.Web.PublishedContentModels.Image' does not contain a definition for 'URL' and no extension method 'URL' accepting a first argument of type 'Umbraco.Web.PublishedContentModels.Image' could be found (are you missing a using directive or an assembly reference?)
Obviously there is something missing that the documentation has omitted. Any assistance much appreciated.
Both of those result in an empty string. I have added another image to the media library and got the same result...
HOWEVER.. while typing this I realise that when setting up, I created a new media type: MyImage and used that. Better go make sure that hasn't messed things up...
Since you inherit from the UmbracoTemplatePage you can get your media by using the below code snippet, which Dave Woestenborghs shows in this article https://24days.in/umbraco-cms/2015/strongly-typed-vs-dynamic-content-access/ - It gives a nice explanation on how to do things whether you're using strongly typed or dynamics. Yes there currently is 2 different ways of achieving the same end result. I'll spare you the dull technical details but it is confusing to figure out especially when one is just starting out and want to render things :-)
Anyhow let's get back to the snippet from Dave's article - It looks like this.
So the in the if check where it says "CurrentPage.Image" you should replace the "Image" part with with the alias of your media property if it's called something else like "Media" or "BackgroundImage" etc.
You should also do this in the line where he is setting the mediaId variable. I have highlighted those parts of the code.
As you can see there is a check to make sure that a media item has actually been picked by an editor in the umbraco backoffice. If there was no check for this then it could result in one of those cryptic yellow screens of death (YSOD's) that you have already experienced. So we can avoid this by making sure there is a value before we try to render the image.
If a media item has been selected we get the id of the media, which we can then pass to Umbraco.Media, which will give us back the media object where the Url among other properties can now be called for showing the media.
Now this should output your image.
I hope my explanation above makes sense otherwise feel free to ask further questions - And I also recommend that you read Dave's articles a couple of times since it's gives some explanation to the different approaches that can be used to render the Umbraco data. Another source of information is this page from the documentation here https://our.umbraco.org/documentation/reference/templating/mvc/views
Thanks for the comprehensive reply. (My problem - see reply to Nigel above - lay elsewhere...)
I had seen the 24Days series previously. One of my problems with it (and many other Umbraco articles) is that it does not feature a date - so it is difficult to establish how relevant the text is to the current version.
(Although one can infer that it is pre-7.4 from the mentions about Models Builder shipping with future versions.)
Hmm, yeah I see that it's not very explicit when one is visiting one or more of the articles out of season. But we do mark the day with 4 and the year is a part of the url. Which makes good sense once the calendar is running during the month of december but might not be very clear when it's out of season. That's a good point - I'll file an issue in our basecamp so we can discuss if we should write the date more clearly somewhere.
NewB - Following guide, pulling out hair
First template worked great. Then tried displaying an image.
I have reduced it to the most basic code possible - trying to work from the Documentation, and getting nowhere.
gives me
Obviously there is something missing that the documentation has omitted. Any assistance much appreciated.
Hey
Try "Url"
Cheers
Nigel
That would be one issue (thanks for spotting it)... but it just raises another:
As I have copy/pasted the media ID straight out of the image's info panel (and it displays if placed into a rich text editor)...
Any thoughts?
Hey Ault
Have you tried just:
or
Cheers
Nigel
Hi Nigel
Both of those result in an empty string. I have added another image to the media library and got the same result...
HOWEVER.. while typing this I realise that when setting up, I created a new media type: MyImage and used that. Better go make sure that hasn't messed things up...
BINGO!!!
A few tests later... That was the issue.
Hi Ault
Since you inherit from the UmbracoTemplatePage you can get your media by using the below code snippet, which Dave Woestenborghs shows in this article https://24days.in/umbraco-cms/2015/strongly-typed-vs-dynamic-content-access/ - It gives a nice explanation on how to do things whether you're using strongly typed or dynamics. Yes there currently is 2 different ways of achieving the same end result. I'll spare you the dull technical details but it is confusing to figure out especially when one is just starting out and want to render things :-)
Anyhow let's get back to the snippet from Dave's article - It looks like this.
So the in the if check where it says "CurrentPage.Image" you should replace the "Image" part with with the alias of your media property if it's called something else like "Media" or "BackgroundImage" etc.
You should also do this in the line where he is setting the mediaId variable. I have highlighted those parts of the code.
As you can see there is a check to make sure that a media item has actually been picked by an editor in the umbraco backoffice. If there was no check for this then it could result in one of those cryptic yellow screens of death (YSOD's) that you have already experienced. So we can avoid this by making sure there is a value before we try to render the image.
If a media item has been selected we get the id of the media, which we can then pass to Umbraco.Media, which will give us back the media object where the Url among other properties can now be called for showing the media.
Now this should output your image.
I hope my explanation above makes sense otherwise feel free to ask further questions - And I also recommend that you read Dave's articles a couple of times since it's gives some explanation to the different approaches that can be used to render the Umbraco data. Another source of information is this page from the documentation here https://our.umbraco.org/documentation/reference/templating/mvc/views
Cheers, Jan
Hi Jan,
Thanks for the comprehensive reply. (My problem - see reply to Nigel above - lay elsewhere...)
I had seen the 24Days series previously. One of my problems with it (and many other Umbraco articles) is that it does not feature a date - so it is difficult to establish how relevant the text is to the current version.
(Although one can infer that it is pre-7.4 from the mentions about Models Builder shipping with future versions.)
Thanks again, Ault
Hi Ault
Happy to hear you managed to solve your issue :-)
Hmm, yeah I see that it's not very explicit when one is visiting one or more of the articles out of season. But we do mark the day with 4 and the year is a part of the url. Which makes good sense once the calendar is running during the month of december but might not be very clear when it's out of season. That's a good point - I'll file an issue in our basecamp so we can discuss if we should write the date more clearly somewhere.
Thanks for the feedback - Happy coding!
/Jan
is working on a reply...