I've created a new class Library and moved all the models into it using the model builder and configuring the JSON file to move it to an external class library using Umbraco 10 and .Net 6.
In my website project (Umbraco 10) I reference the class library (called Umbraco.Models).
In my template (razor) how should I access the page/Doc type created? When I write
UmbracoViewPage
Models does not exist (I've added project reference). ContentModels.Home does exist?
The models are being generated in your own class library, that is correct, but unless you use the setting to set the models namespace they will still be using the default namespace of Umbraco.CMS.Web.Common.PublishedModels.
No thanks Nik, they can remain in the same library/naming convention but I was confused thinking my class library isn't working the way it's supposed to but you guys have explained that well.
So even though it's in a separate library I can continue to use the same path which is nice.
Strongly typed model
Hi
I've created a new class Library and moved all the models into it using the model builder and configuring the JSON file to move it to an external class library using Umbraco 10 and .Net 6.
In my website project (Umbraco 10) I reference the class library (called Umbraco.Models).
In my template (razor) how should I access the page/Doc type created? When I write
UmbracoViewPage
Models does not exist (I've added project reference). ContentModels.Home does exist?
Hi Dean,
You should just be able to do
Hi
Interestingly that worked!
Maybe I misunderstood something here but I was trying a fully qualified name.
This worked!
But this didn't
My models sit in a separate class library (so Home is a class declared as Home.generated.cs.
When I hover over the code you supplied that works, I notice Home is Umbraco.CMS.Web.Common.PublishedModels.Home
So is this mapping to the same object or in a polite way did you forget I mentioned my models are in a separate class library?
Cheers
it will still belong to Umbraco.CMS.Web.Common.PublishedModels unless you change the namespace in the modelsbuilder settings "ModelsNamespace"
Hi Dean,
As Huw says,
The models are being generated in your own class library, that is correct, but unless you use the setting to set the models namespace they will still be using the default namespace of Umbraco.CMS.Web.Common.PublishedModels.
https://docs.umbraco.com/umbraco-cms/reference/configuration/modelsbuildersettings
The setting you need if you want to change their namespace is the "ModelsNamespace" property.
Thanks
Nik
No thanks Nik, they can remain in the same library/naming convention but I was confused thinking my class library isn't working the way it's supposed to but you guys have explained that well.
So even though it's in a separate library I can continue to use the same path which is nice.
is working on a reply...