I have a small problem where I don't know how to code this.
I have created a Media Picker with name "Footer Image" and Alias "footer_image".
I have the following content structure:
Content
en
Home
The Media Picker is placed on the "en" page on a tab named "Content".
I want to display the selected image from the Media Picker in my master template for my webpage.
I have also created a macro that uses razor script and imported that into the master template.
So basically from my razor script macro I want to get the selected image / image path from my Media Picker and then create an img tag or similar to show the image on the web page.
It's pretty typical issue with Umbraco.
First of all you need - get "en" node, you can do it like that:
var enNode = Umbraco.AssignedContentItem.AncestorOrSelf(2);
var imgId = enNode.GetPropertyValue<int>("footer_image");
var imgNode = Umbraco.TypedMedia(imgId);
var imgUrl = imgNode.Url;
Each row is like one step. I hope it will help you.
I I'm using the cshtml file under macro script and not the mvc one.
Though I also tried it with the MVC Partial View without success,
only gets an error saying Error loading Partial View script (file: ~/Views/MacroPartials/footer-image.cshtml)
It isn't really that important on what razor I use, if it's mvc or not though I only found MVC Partial View and that didn't work with your @inherit code.
It's in Developers section if you have Diplo Trace logger or go to "App_Data/Logs/UmbracoTraceLog.txt" . Try to find something about this error and share with me.
Hello again Alex, I appreciate all the help I've got from you!
I have checked now checked the App_Data/Logs/UmbracoTraceLog.txt log without any result. And I can't find a "Developers section" inside my install folder.
Though, I have begun to suspect that I might be missing an assembly or something similar.
First I tried to get the code, you provided, to run without any result and then I tested with your:
@inherits Umbraco.Web.Mvc.UmbracoViewPage
As soon as I added that and had all other code commented out I got the Error loading partial view script.
The default script @inherits tag is
@inherits Umbraco.Web.Macros.PartialViewMacroPage
So when I searched for logs and tried to troubleshoot I navigated inside the "Views" folder inside the root installation folder.
There I found the file "Web.config" that has the following content:
After I had seen the above files content I begun to wounder if I was missing an assembly file, so I navigated to the bin folder.
In the bin folder I found the System.Web.Mvc files but no files with Umbraco.Web.Mvc.* the only files I found there for Umbraco.Web was Umbraco.Web.UI
Get Media Picker value
Hi everyone!
I have a small problem where I don't know how to code this.
I have created a Media Picker with name "Footer Image" and Alias "footer_image".
I have the following content structure:
The Media Picker is placed on the "en" page on a tab named "Content".
I want to display the selected image from the Media Picker in my master template for my webpage.
I have also created a macro that uses razor script and imported that into the master template.
So basically from my razor script macro I want to get the selected image / image path from my Media Picker and then create an img tag or similar to show the image on the web page.
Thx in advance!
Hi Johan
It's pretty typical issue with Umbraco. First of all you need - get "en" node, you can do it like that:
Each row is like one step. I hope it will help you.
Thanks,
Alex
All these lines can look like only one:
Be aware about error checking.
Thanks,
Alex
Thanks for the reply though when copying your code i get an error.
The type or namespace name 'TypedMedia' does not exist in the namespace 'Umbraco'.
Don't know if I'm missing a @using reference or something?
Got the error when I copied the one line code.
When copying the multiline / steps code I get another error:
The type or namespace name 'AssignedContentItem' does not exist in the namespace
Hi Johan
In which file are you coding?
I'm using razor view with
Hi !
I I'm using the cshtml file under macro script and not the mvc one. Though I also tried it with the MVC Partial View without success, only gets an error saying
Error loading Partial View script (file: ~/Views/MacroPartials/footer-image.cshtml)
It isn't really that important on what razor I use, if it's mvc or not though I only found MVC Partial View and that didn't work with your @inherit code.
Thx in advance.
Hi Johan,
Can you check Umbraco Logs?
It's in Developers section if you have Diplo Trace logger or go to "App_Data/Logs/UmbracoTraceLog.txt" . Try to find something about this error and share with me.
Thanks,
Alex
Hello again Alex, I appreciate all the help I've got from you!
I have checked now checked the
App_Data/Logs/UmbracoTraceLog.txt
log without any result. And I can't find a "Developers section" inside my install folder.Though, I have begun to suspect that I might be missing an assembly or something similar.
First I tried to get the code, you provided, to run without any result and then I tested with your:
As soon as I added that and had all other code commented out I got the
Error loading partial view script
.The default script
@inherits
tag isSo when I searched for logs and tried to troubleshoot I navigated inside the "Views" folder inside the root installation folder.
There I found the file "Web.config" that has the following content:
After I had seen the above files content I begun to wounder if I was missing an assembly file, so I navigated to the
bin
folder.In the
bin
folder I found theSystem.Web.Mvc
files but no files withUmbraco.Web.Mvc.*
the only files I found there forUmbraco.Web
wasUmbraco.Web.UI
is working on a reply...