2015-03-19 53 views
0

我創建了一個多節點樹選取器數據類型,我試圖列出作爲foreach循環的一部分的車輛的縮略圖,但是我不斷獲取ID渲染在圖像的src中,我無法獲取圖像的URL。Umbraco 7 MVC Razor - 渲染圖像(多節點樹選取器腳本)

MVC剃刀代碼

@inherits Umbraco.Web.Macros.PartialViewMacroPage 
@using Umbraco.Web 

@* 
    Macro to list nodes from a Multinode tree picker, using the pickers default settings. 
    Content Values stored as xml. 

    To get it working with any site's data structure, simply set the selection equal to the property which has the 
    multinode treepicker (so: replace "PropertyWithPicker" with the alias of your property). 
*@ 

@* Lists each selected value from the picker as a link *@ 

<div class="featuredVehicles"> 
    @foreach (var id in CurrentPage.featuredVehicles.Split(',')) 
    {  

    @*For each link, get the node, and display its name and url*@ 
     var vehicleContent = Umbraco.Content(id); 

     <div class="col-xs-6 col-md-4 col-xs-height"> 
      <a href="@vehicleContent.Url"> 

       @if (vehicleContent.HasValue("vehicleThumbnail")) 
       { 
        var mediaItem = Umbraco.TypedMedia(vehicleContent.GetPropertyValue("vehicleThumbnail")); 
        <img class="featuredVehicleImg img-responsive" src="@vehicleContent.GetPropertyValue("vehicleThumbnail")" alt="@vehicleContent.Name"/>     
       } 
       else 
       {    
        <img class="comingSoon" src="http://placehold.it/650x408" alt="@vehicleContent.Name"> 
       } 

       <strong> 
        <span class="name">@vehicleContent.Name</span> 
       </strong> 

       <span class="desc">@vehicleContent.GetPropertyValue("shortContent")</span> 

       <span class="prx">from, <strong>&pound;@vehicleContent.vehiclePrice</strong> per day</span> 

       <span class="label label-primary moreinfo">More Info</span> 

      </a> 
     </div> 
    } 
</div> 

HTML

<img alt="Pharmaceutical Vehicle One" src="1092" class="featuredVehicleImg img-responsive"> 

回答

1

問題解決了;

這是導致問題的位;

if (vehicleContent.HasValue("vehicleThumbnail")){           
         var dynamicMediaItem = Umbraco.Media(vehicleContent.vehicleThumbnail); 
         <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/> 
        } 
        else 
        {    
         <img class="comingSoon" src="http://placehold.it/650x408" alt="@vehicleContent.Name"> 
        } 

希望這將幫助別人了:-)