Hadi Hariri's Blog

Dynamic types and ASP.NET MVC

Wednesday, 30 December 2009 13:25 by Hadi

If you’re using ViewModels in your ASP.NET MVC applications, know that if working with .NET 4.0, you can now create dynamic view models. And it’s actually very simple to do.

Create an ExpandoObject to represent your ViewModel:

 

image

Declare your view to be of type ViewPage<dynamic>

 

image

 

 

 

And you’re done. Here’s the output:

 

image

 

If you’re using ReSharper, you will get Intellisense once you’ve declared a property once (both in the Action as well as the View).

Categories:  
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

Comments

Comments are closed