I'm having issues with our footer partial which is called from the master/layout template used on all pages.
I've tried a variety of approaches but the model is always null meaning I can't access things like the navigation (umbraco content pickers) and the copyright text (plain text field)
Here you can see that I've tried using a fallback then checked if the model even has anything in it (spoilers, it's null)
Any pointers are welcome, I'm on the latest v13 and using Models Builder. the above is a snippet that shows the inheritance and the bottom of the file where the model is being called
Thanks for replying, I don't think this would work as the footer navigation is stored in a tree node called footer under a different root node called "Global" so "Global > Footer" but the site pages are under the "Home" root node
So it's my layout/master template calling the partial (this will be true for the whole site, not my personal choice but it is how the site was set up by the third party who did the build for version 8)
You could add the the "Footer" content to the ViewBag via the same method as explained before.
Of course it is not the best practice to add all your content to the ViewBag however because you have already implemented this you could extend it and make use of it one more time.
That's fair! It was only later I realised the parallel to the other question. the thing is shouldn't the partial be able to access the content in its doctype without the viewbag?
Maybe I need to look at a different approach entirely for this content as the footer will appear on all pages. It still feels messier than it should, is there maybe a best practice for this organising this kind of structure?
the only choice driving this separation is purely how it was done on the older version of the site
I am a back-end developer (so not that used with the .cshtml side) using Umbraco but if i am not mistaken this is the reason why your @Model is null:
What you are saying is correct: "the thing is shouldn't the partial be able to access the content in its doctype without the viewbag". However this is only the case when you develop a template (.cshtml page) for a specific doctype, not all doctypes have templates.
If you develop a view for a doctype (for example Homepage, so the Homepage.cshtml view) then you can read the values of the content using @Model and display them in the view. However, the Footer doctype is not a page with its own template (there is no page: "https://myumbracosite.com/en/footer") so you cannot read it using @Model. Generic settings such as main menu, footer and site settings cannot (as far as I know) be "injected" into the @Modal property.
In summary: if you are not developing a content page/view for a doctype (for example the Footer partial) it is separate from @Model and you need to retrieve the data in a different way.
Please correct me if i am wrong! I am very interested in other solutions.
Which, depending on your architecture, you can populate when the page loads via a RenderController or you might need a ViewComponent rather than a partial. If you're not passing that object, then it'll always be null as nothing is going to it (unless I've misunderstood how you have this working!).
I'm having trouble working out how to correctly pass the model to the partial.
If I use the models builder model definition in the partial itself it falls over as it's then got two models competing on the page.
Passing it through though is proving quite hard. I'm converting a version 8 site from .NET so I'm getting tripped up a lot trying to work through it as it's quite different functionally.
If I was to swap the viewbag to the "Global" root node could I use that to access it's children on the page? Or would it be better to add footer and header as their own functions?
Partial view issues v13
Hi,
I'm having issues with our footer partial which is called from the master/layout template used on all pages.
I've tried a variety of approaches but the model is always null meaning I can't access things like the navigation (umbraco content pickers) and the copyright text (plain text field)
Here you can see that I've tried using a fallback then checked if the model even has anything in it (spoilers, it's null)
Any pointers are welcome, I'm on the latest v13 and using Models Builder. the above is a snippet that shows the inheritance and the bottom of the file where the model is being called
Pass Model rather than Model.Footer from Master layout to Footer Partial and fetch values from root node directly. Use code like below for that,
var home = (Home)Model.Root();
@home.CopyrightText
Hi Diljith Peter,
Thanks for replying, I don't think this would work as the footer navigation is stored in a tree node called footer under a different root node called "Global" so "Global > Footer" but the site pages are under the "Home" root node
So it's my layout/master template calling the partial (this will be true for the whole site, not my personal choice but it is how the site was set up by the third party who did the build for version 8)
Hopefully this information is helpful!
Thanks, Sandy
Hi Sandy,
Like I explained to you in this thread: https://our.umbraco.com/forum/using-umbraco-and-getting-started/114614-umbraco-v13-content-node-as-a-class-for-use-in-all-views-and-partials
You could add the the "Footer" content to the ViewBag via the same method as explained before.
Of course it is not the best practice to add all your content to the ViewBag however because you have already implemented this you could extend it and make use of it one more time.
Greetings, Joppe
Hi Joppe,
That's fair! It was only later I realised the parallel to the other question. the thing is shouldn't the partial be able to access the content in its doctype without the viewbag?
Maybe I need to look at a different approach entirely for this content as the footer will appear on all pages. It still feels messier than it should, is there maybe a best practice for this organising this kind of structure?
the only choice driving this separation is purely how it was done on the older version of the site
Thanks, Sandy
Hi Sandy,
I am a back-end developer (so not that used with the .cshtml side) using Umbraco but if i am not mistaken this is the reason why your @Model is null:
What you are saying is correct: "the thing is shouldn't the partial be able to access the content in its doctype without the viewbag". However this is only the case when you develop a template (.cshtml page) for a specific doctype, not all doctypes have templates.
If you develop a view for a doctype (for example Homepage, so the Homepage.cshtml view) then you can read the values of the content using @Model and display them in the view. However, the Footer doctype is not a page with its own template (there is no page: "https://myumbracosite.com/en/footer") so you cannot read it using @Model. Generic settings such as main menu, footer and site settings cannot (as far as I know) be "injected" into the @Modal property.
In summary: if you are not developing a content page/view for a doctype (for example the Footer partial) it is separate from @Model and you need to retrieve the data in a different way.
Please correct me if i am wrong! I am very interested in other solutions.
Greetings, Joppe
Hi Joppe,
That makes sense I think. I'll try a few things then come back here
Thanks, Sandy
Hi Sandy,
So when you call your partial, are you passing a populated Footer Model to it?
So guessing you have something like:
@await Html.PartialAsync("Footer")
But you probably need something like:
@await Html.PartialAsync("Footer", myPopulatedFooterObject)
Which, depending on your architecture, you can populate when the page loads via a RenderController or you might need a ViewComponent rather than a partial. If you're not passing that object, then it'll always be null as nothing is going to it (unless I've misunderstood how you have this working!).
Hi Simon,
I'm having trouble working out how to correctly pass the model to the partial.
If I use the models builder model definition in the partial itself it falls over as it's then got two models competing on the page.
Passing it through though is proving quite hard. I'm converting a version 8 site from .NET so I'm getting tripped up a lot trying to work through it as it's quite different functionally.
If I was to swap the viewbag to the "Global" root node could I use that to access it's children on the page? Or would it be better to add footer and header as their own functions?
We used to have:
But now I am struggling to replace this as accessing the global root seems to be harder than I thought.
Thanks, Sandy
Hi Sandy,
So in the old site, how was globalContent defined and populated?
Hi Simon,
Site defined globalContent as:
If I use this now I get:
I fear I am realising how little I actually know about Umbraco XD
Hi Sandy,
Sounds like an annoying error!
So is this
in the view that is calling the partial or is it happening in a service/controller?
Hi Simon,
At the moment it is in the View, though I may just have my logic twisted.
I was using it to get the global root node to then use descendant of type for the footer partial.
I almost wonder if I should just bin the files and start over fresh just so I can get rid of the umbraco 8 stuff
is working on a reply...