views:

70

answers:

1

What are the benefits/demerits of using duck typed view models with asp.net mvc?

Recently I've seen an interesting implementation of a twitter search client, using fluent C# dynamic XML wrapper to pass data from the controller to the view, to wrap XML data.

It seems like a better way to pass data - viewModel.Foo instead of using ViewData["Foo"] or Foo.Bar instead of XElement("Foo").Attribute("Bar").Value in terms of cleaner code - but I assume it will be having performance issues.

A: 

Benefits - less code (literally) and readability (in cotrast to ViewData["foo"] approach).

Drawbacks - you lose strongly typed view model (and that's something i can't live with). Higher dependency on unit tests. And I'm not sure how things like Mvc2 templates/validation can be attached to dynamic view model.


In case you are not familiar with view model idea - take a look at this. It's way much more powerful beast than it seems at first.

Arnis L.