Copied to clipboard

Flag this post as spam?

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


  • Ilias 11 posts 81 karma points
    Mar 09, 2018 @ 10:57
    Ilias
    0

    Error with Model.Content.GetPropertyValue

    Here is part of my code:

    @using Umbraco.Web;
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var mTest = Model.Content.GetPropertyValue<string>("info", true);
    }
    <div>
        @mTest
    </div>
    

    It is impossible to get the content of info property. I am getting the following error: Object reference not set to an instance of an object. From the other side, everything works fine by using:

     @Umbraco.Field("info", recursive: true)
    

    However, I want to use the first approach. I'd appreciate any help on that.

  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Mar 09, 2018 @ 11:09
    Michaël Vanbrabandt
    0

    Hi Ilias,

    could it be that your property info is everywhere empty so null?

    You could add if(!String.IsNullOrEmpty(mTest)) to check if the result is not null or empty.

    Hope this helps.

    /Michaël

  • Ilias 11 posts 81 karma points
    Mar 09, 2018 @ 11:21
    Ilias
    0

    The program does not assign any value to mTest since it stops execution. Moreover, I have already mentioned that there is no problem with

    @Umbraco.Field("info", recursive: true)
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies