I like strongly typed view models in MVC. Typical structure of my site in Razor View Engine includes a page base model that is used in the Layout template and then I use inheritance to add properties to each model or commonly re-used properties. There are various reasons why to avoid dynamic in your models, besides the fact that you cannot use dynamic in master frame using razor.

The problem with model properties instead of something like ViewBag is that your controllers and services can start to grow with logic that shouldn’t really be there.

There are various ways to deal with this, one of them is assigning the properties you want commonly in your view models using filters.

To make the life a bit easier. I wrote ModelFilterBase that looks for a specific model on result execution and triggers OnModelLoaded method, if the model is found.

Real world example

Lets say you want every view model to contain information about the browser that is used. We can create an interface and implement the interface on the view model.

publicinterfaceIBrowserDetails{stringBrowserName{get;set;}}//implement the interface on the model or model basepublicclassHomeModel:IBrowserDetails{publicstringBrowserName{get;set;}//... other properties}

Then, implement the BrowserModelFilter with IBrowserDetails interface as type. Override the OnModelLoaded method and notice the protected model property with IBrowserDetails as type. Also, don’t forget to register the filter.