Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I avoid using strongly typed viewdata?

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.

like image 347
Dane O'Connor Avatar asked Feb 24 '26 08:02

Dane O'Connor


1 Answers

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.

like image 120
tvanfosson Avatar answered Feb 27 '26 02:02

tvanfosson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!