0
votes

I'm using Umbraco 7.5 and ModelsBuilder in "AppData" mode, I have a Settings document type and content node, which of course doesn't have a view (template).

In a global code file, I create an instance of settings node like this:

IPublishedContent Settings = new UmbracoHelper(UmbracoContext.Current).TypedContent(123);

Now, how can I create an initialize the model that is created by ModelsBuilder? Although I can make calls to Settings.GetPropertyValue(...), I want to initialize and use the "SiteSettings.generated.cs" strongly typed model that is generated by ModelsBuilder for me, which already contains the properties I have defined.

Can you please help?

1

1 Answers

1
votes

Ok, here is the answer:

The models generated by ModelsBuilder all inherit from PublishedContentModel, which has a constructor that receives an IPublishContent object as input and instantiate the model object for you. So, the code would be (SiteSettings is the name of the model class):

IPublishedContent settingsNode = new UmbracoHelper(UmbracoContext.Current).TypedContent(123);
var settingsModel = new SiteSettings(settingsNode);