I'm not sure what I'm missing here, but I have a simple page where I have a multiple media picker and I'm just trying to display the images. The.Path property just returns -1,1062
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var ms = ApplicationContext.Current.Services.MediaService;
}
<section id="@CurrentPage.Name" class="one">
<div class="container">
<header>
<h2>
@Html.Raw(Umbraco.ReplaceLineBreaksForHtml(CurrentPage.PictureHeader))
</h2>
</header>
@{
char[] splitChar = { ',' };
string[] ids = CurrentPage.Pictures.ToString().Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
foreach (string id in ids )
{
int imageId = int.Parse(id);
@ms.GetById(imageId).Path;
}
}
</div>
</section>
I can't seem to get the image path returned. I tried getting the .umbracoFile property, but that's not available. I see it in the xml though if I write out the @ms.GetById(imageId).ToXml();
It should work on v7.0.0 but there is a bug which will cause a YSOD if a picked image is then deleted from media, a fairly rare problem. This issue is fixed in v7.0.1 but there is also a workaround for v7.0.0 here
Just for reference in case anyone else has this same issue - if you're using a service or class library and using an image cropper, you'll need to do something like this:
int nodeId = 2374;
var myHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent node = myHelper.TypedContent(nodeId);
string url = node.GetPropertyValue<IPublishedContent>("image").GetPropertyValue<ImageCropDataSet>("umbracoFile")).Src;
If you don't have an image cropper installed, you would adjust that last line to GetPropertyValue
Displaying Images from Multiple Media Picker
Hi,
I'm not sure what I'm missing here, but I have a simple page where I have a multiple media picker and I'm just trying to display the images. The.Path property just returns -1,1062
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var ms = ApplicationContext.Current.Services.MediaService; } <section id="@CurrentPage.Name" class="one"> <div class="container"> <header> <h2> @Html.Raw(Umbraco.ReplaceLineBreaksForHtml(CurrentPage.PictureHeader)) </h2> </header> @{ char[] splitChar = { ',' }; string[] ids = CurrentPage.Pictures.ToString().Split(splitChar, StringSplitOptions.RemoveEmptyEntries); foreach (string id in ids ) { int imageId = int.Parse(id); @ms.GetById(imageId).Path; } } </div> </section>I can't seem to get the image path returned. I tried getting the .umbracoFile property, but that's not available. I see it in the xml though if I write out the @ms.GetById(imageId).ToXml();
I'm surprised this is not easier to do and I have to jump thru all these hoops to get there.
I guess I should have tried a 10 min more...this seems to work for me.
foreach (string id in ids ) { var dynamicMediaItem = Umbraco.Media(id); @dynamicMediaItem.umbracoFile; }Hi John, are you using Umbraco v7?
Jeavon
Actually just realised you said multiple media picker so must be using v7.
If you are using v7.0.1, then try this:
Jeavon
Thanks Jaevon,
I'll give that a try if it works on 7.0.0
I tried 7.0.1 and it doesn't seem to be ready for primetime yet.
John
Hi John,
It should work on v7.0.0 but there is a bug which will cause a YSOD if a picked image is then deleted from media, a fairly rare problem. This issue is fixed in v7.0.1 but there is also a workaround for v7.0.0 here
What issues did you have with v7.0.1?
Jeavon
Thanks Jeavon,
I posted my issues here (look at the bottom post on the first page):
http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/46937-Umbraco-backend-701-not-working
My code displaying from multiple media picker:
@if (Model.HasValue("caseImages")) { foreach (var item in Model.GetProperty("caseImages").Value.Split(',')) { <img src="@Model.MediaById(@item).umbracoFile" alt="" /> } }Just for reference in case anyone else has this same issue - if you're using a service or class library and using an image cropper, you'll need to do something like this:
If you don't have an image cropper installed, you would adjust that last line to GetPropertyValue
For v7.10.x , When check the Pick multiple items of the Media Picker, you can do this to display the images:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.