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:
The problem you are having is how you are calling your partial view.
By using the code:
@Html.Partial("header/headerTopNav")
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:
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:
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.
However, when the partial is added to the view...
I get the following error:
Any thoughts on where I am going wrong?
Thanks in advance.
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):
Then you can call the partial with the following change:
This will pass in your siteSettings variable to the partial.
Hope that helps :-)
Nik
This all makes sense. And your sudo code seemed to be spot on.
Worked a treat.
Excellent, pleased to hear it :-) Congrats on getting it working :-)
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
https://our.umbraco.org/forum/templates-partial-views-and-macros/92520-nav-from-multinode-tree-picker-ancestor-or-self
No worries :-) I've dropped a reply on the thread for you. Hope it helps :-)
is working on a reply...