Copied to clipboard

Flag this post as spam?

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


  • Joshua 2 posts 82 karma points
    Nov 16, 2017 @ 10:00
    Joshua
    0

    GetPropertyValue("").ToString() error

    So i'm trying to add items to a page. Now the size of these items can be configured in the backend with a dropdown(Small, Medium or Large). I'm trying to read the property using GetPropertyValue("alias"). Now to compare this I made a simple if statement.

    var image = Umbraco.TypedMedia(child.GetPropertyValue("itemImage"));
                        var size = child.GetPropertyValue("itemSize").ToString();
                        if (size == "Large")
                                    {
    
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
    
                            </div>
                        }
    

    Now the problem is, if i convert the value to a string it gives me the following error: Object reference not set to an instance of an object.

    The weird thing is that the object I'm trying to convert is not null at all and using visual studio i can see it has that exact value.

    When i'm not converting it is has the correct value, but for some reason the if statement says it's not the same value and just goes on without executing the stuff within the if statement.

  • Ben Palmer 180 posts 866 karma points c-trib
    Nov 16, 2017 @ 18:02
    Ben Palmer
    100

    Not 100% confident about this one but try:

    string size = child.GetPropertyValue<string>("itemSize");
    

    Also, are you sure that child.GetPropertyValue("itemImage") is returning something?

  • Joshua 2 posts 82 karma points
    Nov 17, 2017 @ 08:34
    Joshua
    0

    Yeah you're right.

    child.GetPropertyValue("itemImage") 
    

    it is null indeed, for some reason Visual Studio kept saying the error was in the line above..

    Thanks!

  • Ben Palmer 180 posts 866 karma points c-trib
    Nov 17, 2017 @ 08:57
    Ben Palmer
    1

    Happy to help - let me know if you need more help getting the item image to come through.

    Also just on your point about VS, I've noticed that in view files specifically, it often gets the line number wrong on null instances. It's one of VS's many quirks.

Please Sign in or register to post replies

Write your reply to:

Draft