When it's 'turned on' it will generate strongly typed c# models for each Document Type in Umbraco.
These generated models all implement IPublishedContent so you can cast easily into them, or as they are generated as partial c# classes you can extend them etc... Anyway worth having a look at the first...
If you prefer not to use Modelsbuilder then you'd need to handle mapping the properties yourself., eg
var homepage = new HomePage() {Title = content. Value<string>("title"), Remarks = content.Value<string>("remarks")};
Where content is your IPublishedContent object.
You could make some kind of service or mapper, if the same mappings happen in more than one place.
But check out Modelsbuilder as it takes a lot of the pain out of this kind of work.
IPublishedContent parse to Custom View Model using umbraco 13
Hello, I have problem with my umbraco 13, I want to convert the IpublisedContent to strongly type custom view model.
Example I have Title and Remarks properties in my Home Page, I want to parse this to strongly type custom view model.
Here is my sample custom view model.
This is the backoffice.
Please help.
Hi Rene
First thought is have you considered looking at Modelsbuilder at all...
https://docs.umbraco.com/umbraco-cms/reference/templating/modelsbuilder/introduction
When it's 'turned on' it will generate strongly typed c# models for each Document Type in Umbraco.
These generated models all implement IPublishedContent so you can cast easily into them, or as they are generated as partial c# classes you can extend them etc... Anyway worth having a look at the first...
If you prefer not to use Modelsbuilder then you'd need to handle mapping the properties yourself., eg
var homepage = new HomePage() {Title = content. Value<string>("title"), Remarks = content.Value<string>("remarks")};
Where content is your IPublishedContent object.
You could make some kind of service or mapper, if the same mappings happen in more than one place.
But check out Modelsbuilder as it takes a lot of the pain out of this kind of work.
Regards
Marc
is working on a reply...