Search code examples
asp.net-mvcviewcontrollerserver-sideviewdata

Alternatives to ViewData?


I'm pretty new to MVC, ASP.net, and, well, server-side scripting in general.

I was watching a tutorial video at www.asp.net/mvc where the person was explaining a template. He explained that the controller using viewdata to send information to the view.

Correct me if I'm wrong, but I believe it was used like this:

CONTROLLER: ViewData["PropertyName"] = value;

VIEW: <p><%= ViewData["PropertyName"] %></p>

Is this correct use?

What would be a better way to do it, instead of using ViewData, and what's bad about it?


Solution

  • There are very view situations that I would advocate the use of the ViewData collection for.

    For the most part, I would use Strongly Typed Views with individual View Models for each View.