Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 karma points c-trib
    Jun 20, 2013 @ 10:37
    Craig100
    0

    Error exposing MNTP data in V6.1.1 MVC

    Getting error "'bool' does not contain a definition for 'Content'" in a partial view trying to output data from an Umb Core MNTP (alias "articleList") using:-

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>
    
    @{
        if (Model.Content.HasValue("articleList"))
        {
            String typedMultiNodeTreePickerCSV = Model.Content.GetPropertyValue<string>("articleList");
            IEnumerable<int> typedPublishedMNTPNodeListCSV = typedMultiNodeTreePickerCSV.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x));
            IEnumerable<IPublishedContent> typedMNTPCollectionCSV = Umbraco.TypedContent(typedPublishedMNTPNodeListCSV).Where(x => x != null);
            foreach (IPublishedContent item in typedMNTPCollectionCSV)
            {     
                <p>@item.Name</p>         
            }   
        }    
    }

    This is taken from http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Multi-Node-Tree-Picker but changing the @using Umbraco.Core.Dynamics; for @inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic>

    This is my first MVC site so I'm slowly adjusting to the new API and syntax, which I'm enjoying.

    Any advice appreciated.

    Cheers,

    Craig

     

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 20, 2013 @ 10:40
    Jeavon Leopold
    0

    Hey again,

    When you render this partial what model do you pass?

    Thanks,

    Jeavon

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 20, 2013 @ 10:50
    Jeavon Leopold
    2

    This is how I do it, which works perfectly.

    My partial:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
        @{
        if (Model.HasValue("articleList"))
        {
            String typedMultiNodeTreePickerCSV = Model.GetPropertyValue<string>("articleList");
            IEnumerable<int> typedPublishedMNTPNodeListCSV = typedMultiNodeTreePickerCSV.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x));
            IEnumerable<IPublishedContent> typedMNTPCollectionCSV = Umbraco.TypedContent(typedPublishedMNTPNodeListCSV).Where(x => x != null);
            foreach (IPublishedContent item in typedMNTPCollectionCSV)
            {     
                <p>@item.Name</p>         
            }   
        }    
    }
    
    Called in my view, passing Model.Content as Model
    @Html.Partial("MNTPPartial", Model.Content)
  • Craig100 1136 posts 2523 karma points c-trib
    Jun 20, 2013 @ 10:59
    Craig100
    0

    There you have me, I don't really know.

    It's rendered in the home page (home.cshtml) with @inherits Umbraco.Web.Mvc.UmbracoTemplatePage using @Html.Partial("HomePageArticleList",false).

    Does that tell you?

    Craig

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 20, 2013 @ 11:02
    Craig100
    0

    Ah, our posts crossed. Altered my code to yours and it worked perfectly:)  I'll pick the changes out of it to work out what's going on. 

    Many thanks,

    Craig

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 20, 2013 @ 11:19
    Jeavon Leopold
    0

    Excellent! Main difference is just passing Model.Content as the Model to the partial

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 20, 2013 @ 12:17
    Jeavon Leopold
    0

    You got me thinking, if you want to, your partial can inherit from UmbracoTemplatePage instead of UmbracoViewPage, then your code can be the same within the partial as it is in the View.

    e.g

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{              
        if (Model.Content.HasValue("articleList"))
        {
            String typedMultiNodeTreePickerCSV = Model.Content.GetPropertyValue<string>("articleList");
            IEnumerable<int> typedPublishedMNTPNodeListCSV = typedMultiNodeTreePickerCSV.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x));
            IEnumerable<IPublishedContent> typedMNTPCollectionCSV = Umbraco.TypedContent(typedPublishedMNTPNodeListCSV).Where(x => x != null);
            foreach (IPublishedContent item in typedMNTPCollectionCSV)
            {     
                <p>@item.Name</p>         
            }   
        }    
    }
    @Html.Partial("MNTPPartial",Model)
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 20, 2013 @ 12:26
    Jeavon Leopold
    1

    Sorry, one last thought for you, have you seen this package? http://our.umbraco.org/projects/developer-tools/umbraco-core-property-editor-converters

    Then you would not even need to use this code to process the string values, instead you would just go

       @{
            var typedMultiNodeTreePicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("articleList");
            foreach (var item in typedMultiNodeTreePicker)
            {       
                <p>@item.Name</p>           
            }       
        }

     

Please Sign in or register to post replies

Write your reply to:

Draft