Copied to clipboard

Flag this post as spam?

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

  • Ault Nathanielsz 27 posts 121 karma points
    Jun 15, 2018 @ 09:54
    Ault Nathanielsz

    Models binding and doctypes (NewB)

    Hi All,

    I am using the AppData version of ModelsBuilder in V7.10.4

    I have two doctypes: webpage and globalsettings.

    Using the webpage doctype I have a home page with several children - pretty much what you'd expect.

    I also have a single globalsettings node at the root. One of its fields is a multinode-tree-picker called "topNav" which I have used to select the pages that will appear in the top navigation.

    I use the following declaration at the beginning of my master view:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.WebPage>
    @using ContentModels = Umbraco.Web.PublishedContentModels;

    This works fine, and allows me to get details from the current page thusly:


    I have added a partial to the view. I assume that to access the data in Globalsettings, I need to inherit from that model.

     inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.GlobalSettings>

    However, when the partial is added to the view...


    I get the following error:

    Cannot bind source content type Umbraco.Web.PublishedContentModels.WebPage to model content type Umbraco.Web.PublishedContentModels.GlobalSettings.

    Any thoughts on where I am going wrong?

    Thanks in advance.

  • Nik 982 posts 3991 karma points MVP c-trib
    Jun 15, 2018 @ 10:01

    Hi Ault,

    The problem you are having is how you are calling your partial view.

    By using the code:


    you are, in effect, passing in the current page to the partial view which is why you are getting the binding error.

    What you need to do is retrieve your global settings node by doing something like this (Please note this is sudo code as I can't recall the exact code you'll need):

    var siteSettings= Umbraco.TypedContentAtRoot().FirstOrDefault(x => x.ContentType.Alias.Equals("globalSettings")).OfType<GlobalSettings>(); 

    Then you can call the partial with the following change:

    @Html.Partial("header/headerTopName", siteSettings)

    This will pass in your siteSettings variable to the partial.

    Hope that helps :-)


  • Ault Nathanielsz 27 posts 121 karma points
    Jun 15, 2018 @ 17:18
    Ault Nathanielsz

    This all makes sense. And your sudo code seemed to be spot on.

    Worked a treat.

  • Nik 982 posts 3991 karma points MVP c-trib
    Jun 15, 2018 @ 18:09

    Excellent, pleased to hear it :-) Congrats on getting it working :-)

  • Ault Nathanielsz 27 posts 121 karma points
    Jun 22, 2018 @ 10:38
    Ault Nathanielsz

    Nik, if it's not too cheeky to ask, I have a follow-on to this question. Not sure if you saw it, but I'd appreciate any insight you may have.

    Thanks, Ault

  • Nik 982 posts 3991 karma points MVP c-trib
    Jun 22, 2018 @ 11:32

    No worries :-) I've dropped a reply on the thread for you. Hope it helps :-)

Please Sign in or register to post replies

Write your reply to: