Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm studying all posibilities to use a strongly types view in Umbraco.
The hybrid framework version 1 has using a base class inheriting from RenderModel and the new V7 is using a base class inheriting from PublishedContentModel
It seems that all model builders (http://our.umbraco.org/projects/developer-tools/ditto/ditto-feedback/56704-Similar-as-my-project) are generating ViewModel classes based on PublishedContentModel (due to the new IPublishedContentModelFactory? https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/IPublishedContentModelFactory)
If I want to create my ViewModel (by hand), still have access to umbraco content and init it from a custom RenderMvcController class, is it preferable to inherit from RenderModel or from PublishedContentModel ?
What is the difference/pro/cons ?
The only thing that I know so far is that if my viewModel inherit from RenderModel, then the Master view of the site can still "Umbraco.Web.Mvc.UmbracoTemplatePage" and I can use the strongly type view only where I want.
Two different beasts here.
PublishedContentModel is the base class for strongly-typed content models factored by the new IPublishedContentModelFactory at content cache level - ie all content now can be a strongly typed class, eg Umbraco.TypedContent(123) would return an object that is a NewsItem instance.
RenderModel is the base class for view models ie the traditional "M" in "MVC".
Unless you use the IPublishedContentModelFactory (and a model generator of some sort) you are not concerned by PublishedContentModel.
In any case, a pure view model would need to inherit from RenderModel. Now, the content in that view model may inherit from PublishedContentModel. Again two different things here.
Jeroen can prob. comment on why the view models in the Hybrid framework inheir from PublishedContentModel (assuming that's really the case).
Many thanks !
For the hybrid framework vNext it's a "bit" more complex, it uses both !
It uses PublishedContentModel for the auto generated classes from the Zbu.ModelBuilder but then it also has a MasterModel generic class (that the ViewModel do not inherited) and a "CreateMagicModel" method that creates an instance of the MasterModel templated as the view class like :
MasterModel<Newsoverview> myViewModel = ModelLogic.CreateMasterModel() as MasterModel<Newsoverview>;
The part of the Hybrid Framework where both are used is something that Stephan and I wrote together while we were at the retreat this year :-). This way the models from the Models Builder don't need to inherit from the RenderModel, but we can still add extra properties which can be used at the masterpage. It's also possible to just let a page inherit from Umbraco.Web.Mvc.UmbracoTemplatePage and everything should still work. That's part of why it's called "Hybrid". I almost don't use that anymore because with Umbraco.Web.Mvc.UmbracoViewPage<MasterModel<Home>> you have all your properties strongly typed available without doing anything extra.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted