Why can’t _ViewStart.cshtml access the ViewBag object?

In short… Use the controller’s view bag.

ViewContext.Controller.ViewBag.MyVar = "myVal";

and

@ViewContext.Controller.ViewBag.MyVar

===============================================================

There is good information here: http://forums.asp.net/post/4254825.aspx

===============================================================

Generally, ViewData[“StoreName”] is same as ViewBag.StoreName

Also, Controller.ViewData[“StoreName”] = Controller.StoreName =
ViewContext.Controller.ViewBag.StoreName
=ViewContext.Controller.ViewData[“StoreName”]

But every view and partial view gets its own instance of viewdata.

http://jeffreypalermo.com/blog/viewdata-mechanics-and-segmentation-excerpt-from-asp.net-mvc-in-action/

===============================================================

There is a another solution here: https://stackoverflow.com/a/4834382/291753

===============================================================

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)