Copied to clipboard

Flag this post as spam?

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


  • Jon 47 posts 290 karma points
    Aug 15, 2016 @ 14:30
    Jon
    0

    Getting Image path from Image Id? [SOLVED]

    How do I get the path og the images/files that I from Ids ?

    @foreach (var item in galleryCollection) {
    var imgArr = item.billeder.ToString().Split(new string[] { "," }, StringSplitOptions.None);
    
        <p>@item.Name</p>
        <p>@item.argang</p>
    
            foreach(var imgId in imgArr){
    
                <p> @imgId <br></p>
    
            }
    }
    

    I have tried something like this – which I've been lucky with before:

    var Img =  Library.MediaById(imgId.Image);
    var ImgPath = Umbraco.Media(imgId).Url;
    

    But it gives me an error:

    Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: The name 'Library' does not exist in the current context

    Source Error:

    Line 146:   foreach(var imgId in imgArr){
    Line 147:                                           
    Line 148:   var Img =  Library.MediaById(imgId.Image);
    Line 149:   var ImgPath = Umbraco.Media(imgId).Url;
    Line 150:   
    
  • Jon 47 posts 290 karma points
    Aug 15, 2016 @ 14:46
    Jon
    101

    Solved it by playing around :-)

    foreach(var imgId in imgArr){
    
        var Img =  Umbraco.Media(imgId);
        var ImgPath = Umbraco.Media(imgId).Url;
    
        <img src="@ImgPath"> <br>
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft