Old blog. Blog moved to thomasgathings.com
I would delete this...but I don't see the option

Sharing a Generic ViewModel with your master page

Friday, November 13, 2009 2:08 PM
If you have a generic ViewModel, such as ContosoViewModel<TModel>, you can share this with the master page, to an extent, by implementing an interface to the data your shared master might need. This will allow you to avoid using things like ViewDataDictionary for something like a 'Current Customer Id'.
 
so, here's a sample class signature for a generic view model:

public

class EmsViewModel<TModel> : IEmsViewModel
 
 
and here is a typical view's Inherits attribute:

Inherits

="System.Web.Mvc.ViewPage<EmsViewModel<Finding>>"
 
and lastly, here is the master page's Inherits attribute:

Inherits

="System.Web.Mvc.ViewMasterPage<IEmsViewModel>"
 


  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Feedback

No comments posted yet.


Post a comment