Copied to clipboard

Flag this post as spam?

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


  • Christian Hansen 32 posts 182 karma points
    Apr 16, 2018 @ 12:52
    Christian Hansen
    0

    Get image from media picker with leblender?

    Hello,

    Im trying to get image url from Media Picker. I have created a grid editor with LeBlender Editor.

    But i cant figure out how to get image url from media picker. Here is what i have done so far:

    @inheritsUmbracoViewPage< Lecoati.LeBlender.Extension.Models.LeBlenderModel​>
    
    <section class="section-content-module">
        @{
            foreach (var item in Model.Items)
            {
                var modelType = Umbraco.TypedContent(item.GetValue("ModelType")).UrlName;
                var idString = item.GetValue("TekstFarve");
                int id = idString.AsInt();
                var Farve = umbraco.library.GetPreValueAsString(id).Split(' ')[0];
    
                var MultiMediaPicker = item.GetValue<IEnumerable<IPublishedContent>>("Billede");
    
                if (modelType == "model-1-type-1")
    
                {
                    <div class="row model1-type1 text-color-@Farve">
                        <div class="col-12 col-md-6 text-element">
    
                        </div>
                        <div class="col-12 col-md-6 image-element">
                            <img class="test" src="@Umbraco.TypedMedia(item.GetValue<IPublishedContent>("Billede")).Url"/>
                        </div>
                    </div>
                }
                else
                {
    
                }
            }
        }
    </section>
    

    I just get this error: Object reference not set to an instance of an object. Can anyone help?

  • Christian Hansen 32 posts 182 karma points
    Apr 17, 2018 @ 13:37
    Christian Hansen
    0

    Figured it out my self:

    @{var imageUrl = item.GetValue<IPublishedContent>("Billede").Url;
                    }
                    <img class="img-fluid" src="@imageUrl" alt="img" />
    
  • Adrian Wu 53 posts 266 karma points
    Aug 16, 2018 @ 14:09
    Adrian Wu
    0

    Hi, Christian, I have the same issue.

     var imageObj= image.GetValue<IPublishedContent>("image");
                var url  = imageObj.Url ;
    

    My code also throws a "Object reference not set to an instance of an object."

    Any idea?

    Thanks,

    A

  • Garðar Þorsteinsson 95 posts 468 karma points
    Aug 16, 2018 @ 14:21
    Garðar Þorsteinsson
    1

    Hi Adrian,

    First always check if image is not null. Maybe the image will be deleted later and then the page would crash.

    var imageObj= image.GetValue<IPublishedContent>("image");
    if (imageObj != null) {
      var url  = imageObj.Url;
     }
    

    I have had issues that sometimes I would need to restart the site to get the property registered correctly.

    If that does not work then it would be helpful if you would write out what kind of an object you are getting.

    @image.GetValue<string>("image"); 
    

    If it writes out an integer then you are using the old Media picker.

  • darzren 4 posts 83 karma points
    Feb 09, 2020 @ 07:07
    darzren
    0

    Hi, I having the same problem but I am using Umbraco 8.

    I encountered this erro Object reference not set to an instance of an object.'

    with below code.

    <a href="#" class="logo">
                                         <img src="@Umbraco.Media(@Umbraco.AssignedContentItem.GetProperty("sitelogo").GetValue()).Url" />
                                     </a>
    
Please Sign in or register to post replies

Write your reply to:

Draft