Copied to clipboard

Flag this post as spam?

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


  • Craig100 1078 posts 2366 karma points c-trib
    Jul 06, 2017 @ 18:04
    Craig100
    0

    Typed MuliNodeTreePicker in Partial View

    Umb 7.6.3

    Just upgraded a site to 7.6.3 (from 7.4.1) and recoding views and partials to use ModelsBuilder.

    I have a partial that puts out a list of news articles picked using an MNTP. However, can't get it to work using the documented method.

        @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    
        @{              
            if (Model.HasValue("articleList"))  {
                var articleList = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("articleList");
    
                foreach (var article in articleList) {
    
                   Some more code    
                }
            }
         }
    

    I get a YSOD saying Object reference not set to an instance of an object. on the foreach line.

    The page that invokes this uses:-

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Home>
    @using ContentModels = Umbraco.Web.PublishedContentModels
    

    and

    @Html.Partial("HomePageArticleList", Model)
    

    The master page uses:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>

    I'm a fan of ViewPage rather than TemplatePage ;)

    Any advice appreciated.

    -Craig

  • Victor 25 posts 146 karma points
    Jul 06, 2017 @ 18:42
    Victor
    0

    I don't know if I am right, but I believe you've to use Model.Content.HasValue or Model.Content.GetProperty.

    As for the article in the articleList, if articleList are children of the Model.Content, I normally check if the Model.Content.Children are greater than 0.

    if (Model.Content.Children.Count() > 0)
    {
        foreach (var article in Model.Content.ChildrenAsList)
        {
    
        }
    }
    
  • Craig100 1078 posts 2366 karma points c-trib
    Jul 06, 2017 @ 18:48
    Craig100
    0

    Hi Victor,

    When using UmbracoViewPage, the Model doesn't have a .Content. So it all appears to work above the foreach line, but I'm suspecting some issue with the built-in property value converters which is why it's complaining.

  • Craig100 1078 posts 2366 karma points c-trib
    Jul 06, 2017 @ 20:20
    Craig100
    100

    Ouch,

    Turns out the MNTP in 7.6.3 is a different beast to the one in 7.4.1. I deleted it and reinstated using the new datatype and all is now working!

    Painful.

  • 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