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 34 posts 204 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 [email protected]">
                        <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 34 posts 204 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 98 posts 473 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>
    
  • Vidir T. 2 posts 72 karma points
    Sep 10, 2020 @ 07:05
    Vidir T.
    0

    Hi!

    I have tried everything you write and other things I have googled. My version is 7.12.4 I have created different landing pages and inserted e.g. Top-Logo (topLogo) in document types with media picker (for choosing logo) and in Partial Views a Top-Logo.cshtml with first line

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    and every kind of code here under ...

    <img src="@Umbraco.Media(@Umbraco.AssignedContentItem.GetProperty("topLogo").GetValue()).Url" width="200" height="46" alt="" />
    

    and

    @{
        var topLogo = Umbraco.TypedMedia(item.GetPropertyValue<int>("topLogo"));
          if (topLogo != null)
          {
            <img src="@topLogo.Url" width="200" height="46" alt="" />
          }
        }
    

    It looks hopeless to me ..

    Anyone have a suggestion?

  • Vidir T. 2 posts 72 karma points
    Oct 06, 2020 @ 08:44
    Vidir T.
    0

    resolved after 3 weeks of struggling with this problems.

            @{
    

    var pickedMediaId = Model.Content.GetPropertyValue

    We are considering moving our web platform to wordpress which has plugins for everything you need instead of umbraco systems where you have to reinvent the wheel as soon as you need to insert a function.

    Also, it seems like no one is active on this forum anymore. Umbraco was certainly good for its time in 2008 but now is 2020 and this is too old.

    Bye!

Please Sign in or register to post replies

Write your reply to:

Draft