Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • hassanisback 8 posts 78 karma points
    Feb 08, 2018 @ 14:59
    hassanisback
    0

    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.

    //template
    @foreach(var item in selection){
    
      <section >
      @Html.Partial("/Views/Partials/Sections/" + @item.SectionType + ".cshtml", new ViewDataDictionary {
            {"text",   @item.PageContent},
            {"image", @item.Image},
            {"heading", @item.Heading}
    
        })
      </section>  
      }
    
    //Partial view
    @{
    

    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; }

  • Anders Bjerner 487 posts 2990 karma points MVP 8x admin c-trib
    Feb 08, 2018 @ 16:48
    Anders Bjerner
    0

    What type is item and item.Image?

    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.

Please Sign in or register to post replies

Write your reply to:

Draft