ASP.NET MVC Strongly Typed vs. Dynamically Typed Views
Given the benefits of using strongly typed views to eliminate typed errors and the use of lambda expressions why would one use a dynamically type开发者_如何学God view? When I use them I don't feel as safe as with strongly typed views. Am I missing something? Is there a special use for them? =)
Regards RaVen
you are not because strongly typed views gives you ease of use and many benefits. If you have complex model which may contain list instance, other object than also FormViewModel helps you. so there are very few scenario where you really need a dynamically typed view. e.g. I have Product view and I need to show Categories on that, so i created separate view model and i used it for Product and list of categories.
public class ProductViewModel
{
public Product Product { get; set; }
public List<Category> Categories { get; set; }
}
Major disadvantage with dynamically typed view is that you need to write large amount of code as compare to strongly typed views.
There may be a use, for instance if you have a view which uses reflection or whatever to gather data from any object (could be a property grid or whatever).
精彩评论