Monday, 5 May 2014

Using ViewBag in _ViewStart.cshtml

Trying to set or get some value to/from ViewBag in _ViewStart.cshtml will throw an error when you run the app. There is a workaround for this using ViewContext.Controller.ViewBag.

Here is some sample code

ViewContext.Controller.ViewBag.StoreName = "My New Store";

...

@ViewContext.Controller.ViewBag.StoreName

Read more >>

ViewData mechanics and segmentation

No comments:

Post a Comment