ViewModel with Block without a Controller

I am trying to create some consistency to my blocks (i.e. title, padding, background-color) so I created a layout for a block. I followed the IPageViewModel and created a IBlockViewModel<T> and that is the model of my layout class. T has properties about the block title, background-color, etc.. I followed the same procedures as how the pages are done from the Alloy Sample. 

That works great when I have a block that has a controller,  but for simple blocks that just display a few properties I don't have a controller (for performance reasons). The problem is that the model that is getting passed to those views is Castle.Proxies.[MyBlock].  I need it to be IBlockViewModel<T>. Is there anyway I can adjust the model that is getting passed in without creating a Controller for all my blocks?

Is there an alternative to what I am trying to do?  Please any suggestions would be greatly appreciated.

Mike

#183089 Oct 04, 2017 18:58
  • Member since: 2011

    why not just implement interface for all blocks that share common properties and then cast it to that interface inside view? why you need block view model? and btw, page view model is evil either ;)

    #183108 Oct 05, 2017 13:43
  • The interface will probably work for me. I will have to adjust some of my ViewModels to implement that interface and expose some of those properties.  Thanks for the suggestion. Why do you see PageViewModel is evil?

    #183148 Oct 05, 2017 18:32
  • Member since: 2011

    http://marisks.net/2015/05/18/episerver-strongly-typed-layout-model-without-ipageview/

    #183165 Oct 06, 2017 7:28