2

Hello stackoverflow people hope you can help me with maybe a simple question, but couldn't find a solution elsewhere and I have just been working with umbraco for a week now and have never used the mvc part before so all is new for me.

So the big problem is how I make a macro to show these images I choose from the multiple media picker the macro should just end with showing.

<img src="img1.gif" height="50" width="50">
<img src="img2.gif" height="50" width="50">

And so on depending on how many images there is. (the size is just an exempel)

I tryed somthing like this

 @var selectedMedia3 = @Library.MediaById(Model.mainImage);
      <img src="@selectedMedia3.umbracoFile" width="@selectedMedia3.umbracoWidth" height="@selectedMedia3.umbracoHeight" alt="@selectedMedia3.Name"/>                       
    }

But I dont know how to parse the id of the image to the macro. and when I choose more than one file I need a loop, but dont know how to loop the multiple media picker data, so im a little lost by now.

4

3 回答 3

7

您能告诉我们您使用的是什么版本的 Umbraco。近年来,Umbraco 在各种版本中经历了许多根本性的变化。下面的代码应该引导您使用 propertyAlias partnersLogos为Umbraco 7 Multiple Image picker正确的方向。

    @if (Model.Content.HasValue("partnersLogos"))
    {
        var partnersImagesList =  Model.Content.GetPropertyValue<string>("partnersLogos").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var partnersImagesCollection = Umbraco.TypedMedia(partnersImagesList).Where(x => x != null);
        foreach (var partnerImage in partnersImagesCollection)
        {
            <img src="@partnerImage.Url" alt="partners logo" />
        }
    }
于 2014-03-06T09:33:16.953 回答
1

如果有人和我一样犯了同样的错误,并且没有意识到现在过时的媒体选择器和新的媒体选择器“Umbraco.MediaPicker2”(至少从 7.6.1 开始)之间存在差异,那么请阅读 Umbraco 上的文档网站。

https://our.umbraco.org/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker2

@{
    var typedMultiMediaPicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("sliders");
    foreach (var item in typedMultiMediaPicker)
    {
        <img src="@item.Url" style="width:200px"/>
    }
}
于 2017-07-17T20:26:06.340 回答
0

我不太确定您的问题是如何在 umbraco 中设置 MVC 或从图像选择器中获取值。

但是,如果您想在 umbraco 中使用 MVC 启动,请查看:http: //24days.in/umbraco/2013/creating-reusable-code-in-mvc-apps/

于 2013-12-11T22:27:52.870 回答