views:

441

answers:

3

I'm enjoying the lack of "magic strings" in my views and controllers but are there any draw backs to this approach?

It doesn't seem like there are. I've read blog entries here and there implying otherwise though.

+7  A: 

The proliferation of models, in the extreme case to model-per-action, to support additional view properties that may not be directly related to the data model. For example if your view is different depending on a role, you'll need to create a new model to encapsulate the data model and the role-related settings. The same effect could be achieved by using the data model as the view model and adding a few settings to the ViewData via "magic strings."

EDIT This is not a reason to "avoid" strongly-typed views, but to give some balance to choosing when to create a new, view-specific model rather than use an existing model and extend it with ViewData properties.

tvanfosson
+1  A: 

I wouldn't recommend avoiding to use strongly typed viewdata, but I'm sure there are some that would disagree. I could understand if you were doing rapid prototyping and you were still messing around with what data to display. Strongly typing will give you a much better experience debugging and coding. Also, spending the time thinking about your viewdata will give you a better understanding of your design and should ultimately lead to better quality code.

ajma
I agree. Strongly typed will be, and already is, my main path. Just looking for some things to watch out for :). I'd be surprised if making strongly typed views is always a good idea. But I'd happily be surprised if it is.
TheDeeno
+1  A: 

As far as I know there is no single disadvantage of strongly typed viewdata. I don't understand why the magic strings and anonymous object are part of the MVC framework anyway. I try to avoid them all. You don't want to pass arguments of the type object around in the rest of the code, so why would you do it in the UI?

Paco
do you mean no single disadvantage?
Gilligan
Yes, that was a typo.
Paco