1

It seems like most people are leaning towards creating single ModelViews for each view (Thunderdome Principle) in lieu of stuffing in weakly typed items into the ViewData dictionary.

So, with this in mind, for what tasks should the ViewDictionary be used for then? Really small one-off views? Don't use it at all?

1
  • I recommend having a look at this blog post. You obviously can have everything strongly typed with minimal effort! :) Commented Jun 17, 2009 at 20:40

3 Answers 3

3

Never, keep everything strongly typed. Helps with refactoring, that enough is reason alone.

Sign up to request clarification or add additional context in comments.

Comments

3

MasterPages strike me as a place where it's tough to get around them. Let's say you have a standard place on all your pages where error messages are going to be displayed. You could theoretically strong type the MasterPage and make sure that all view models inherit from some base class that gives you strong-typed access to the variable for setting the error message in your master page, but that seems like overkill. It's much more reasonable to do something like:

ViewData["ErrorMessage"] = "This is an error message";

and have your master page have a section displaying it:

<div class="error_message"><%= ViewData["ErrorMessage"] %></div>

Comments

0

I think the question is: use strongly-typed Views on not and when?. If your Views are not strongly-typed then you will be using ViewDataDictionary (mostly for simple/small apps). If you are using Unit Testing it is better to have View Model which can be simply tested.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.