Hi
I am trying to pass the image url from the template to the partial view. The problem is that it show only id instead of the image. Now I tried many ways to get the url from the id but failed.
Here is the code if you guys have any idea to solve.
Thanks in advance.
If you're using ModelsBuilder, item.Image is probably already an instance of IPublishedContent, and you should then be able to get the URL via item.Image.Url.
Passing imageUrl from template to partial view
Hi I am trying to pass the image url from the template to the partial view. The problem is that it show only id instead of the image. Now I tried many ways to get the url from the id but failed. Here is the code if you guys have any idea to solve. Thanks in advance.
var text = ViewData["text"].ToString(); var header = ViewData["heading"].ToString(); var imageUrl = ViewData["image"];
//get the image url //var imageId = ViewData["image"]; //var umbHelper = new UmbracoHelper(UmbracoContext.Current); //var content = umbHelper.Media(imageId); //var content = Umbraco.Media(imageId); //var imageUrl = content.Url; //var media = umbraco.library:GetMedia(imageId, 'false'); //var imageUrl = imageId.Url; }
What type is
item
anditem.Image
?If you're using ModelsBuilder,
item.Image
is probably already an instance ofIPublishedContent
, and you should then be able to get the URL viaitem.Image.Url
.is working on a reply...