Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • fabrice 104 posts 227 karma points
    Oct 15, 2014 @ 14:31

    ViewModel : PublishedContentModel Vs RenderModel


    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 ( are generating ViewModel classes based on PublishedContentModel (due to the new IPublishedContentModelFactory?

    Question :

    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.

    Many thanks


  • Stephen 767 posts 2266 karma points c-trib
    Oct 15, 2014 @ 18:33

    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).

    Making sense?

  • fabrice 104 posts 227 karma points
    Oct 16, 2014 @ 08:27

    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>;

  • Jeroen Breuer 4861 posts 12132 karma points MVP 3x admin c-trib
    Oct 16, 2014 @ 09:40
    Jeroen Breuer

    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. 


Please Sign in or register to post replies

Write your reply to: