Hi this whole Series is great, especially as I'm trying to get to grips with MVC as opposed to the Portal version.
I have a query as I'm tying to implement the simple approach. I have set up the ViewBag as above however I am using the TemplateResult method rather than View.
The ViewBag Properties aren't showing on the page and I wonder if that has anything to do with use of TemplateResult?
ViewBag.MetaPageDescription = node.GetInheritedValue("DocumentPageDescription");
ViewBag.MetaPageKeyWords = node.GetInheritedValue("DocumentPageKeyWords");
return new TemplateResult(node.DocumentID);
Lead Product Evangelist @Kentico, Founding partner @craftbrewingbiz. love to learn / teach web dev & software engineering, collecting vinyl records, mowing my lawn, craft 🍺
I believe for Template pages you need to specify a Layout, which means whatever you've done for your primary site _Layout.cshtml you will need to do in the Template page's layout as well to get Site Meta information to work correctly.
ViewBag should work fine even in this scenario (however I haven't actually tested it).
Use MVC layouts with the template view for any shared output code (based on your requirements, you can use your site's main layout, a dedicated layout for page templates, etc.).
This can be done through an explicit definition at the top of the Razor file:
I had already set the Layout of the template file and I could see elements from my _Layout file (for example the header), however it seems to me that the ViewBag variables set in the controller were not being passed through.
To get round this I decided to do the following on the template file;
Lead Product Evangelist @Kentico, Founding partner @craftbrewingbiz. love to learn / teach web dev & software engineering, collecting vinyl records, mowing my lawn, craft 🍺
Hi this whole Series is great, especially as I'm trying to get to grips with MVC as opposed to the Portal version.
I have a query as I'm tying to implement the simple approach. I have set up the ViewBag as above however I am using the TemplateResult method rather than View.
The ViewBag Properties aren't showing on the page and I wonder if that has anything to do with use of TemplateResult?
@oliverfurmage
I believe for Template pages you need to specify a Layout, which means whatever you've done for your primary site
_Layout.cshtml
you will need to do in the Template page's layout as well to get Site Meta information to work correctly.ViewBag
should work fine even in this scenario (however I haven't actually tested it).On the docs page for MVC Page Templates it mentions needing to specify a layout for the template Razor file.
This can be done through an explicit definition at the top of the Razor file:
Or through a
_ViewStart.cshtml
file to set the layout for an entire subfolder.@seangwright
I had already set the Layout of the template file and I could see elements from my _Layout file (for example the header), however it seems to me that the ViewBag variables set in the controller were not being passed through.
To get round this I decided to do the following on the template file;
Interesting! Good to know there is a solution like this 🧐.