I have the default _ViewStart.cshtml in my /Views folder. I’d like to be able to access my ViewBag object so I can set the default title for all my views.
However, with:
@{
Layout = "~/Views/Shared/SiteLayout.cshtml";
ViewBag.Title = "bytecourse - Online Courses in Technology";
}
I get “The name ‘ViewBag’ does not exist in the current context” as a runtime error.
What do I need to do?
In short… Use the controller’s view bag.
and
===============================================================
There is good information here: http://forums.asp.net/post/4254825.aspx
===============================================================
===============================================================
There is a another solution here: https://stackoverflow.com/a/4834382/291753
===============================================================