Home »  Dot Net MVC Tutorial »  MVC Viewbag

MVC Viewbag

MVC Viewbag

  • MVC Viewbag helps to maintain data when you move from controller to view.
  • MVC Viewbag Used to pass data from controller to corresponding view.
  • Short life means value becomes null when redirection occurs. This is because their goal is to provide a way to communicate between controllers and views. It is a communication mechanism within the server call.
  • MVC ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.
  • MVC ViewBag does not require typecasting for complex data type.
  • MVC ViewBag is actually a wrapper around MVC ViewData.

MVC ViewBag Example :

  public ActionResult Index()  {      ViewBag.SiteName = "QuickToStudy";      return View();  }  

MVC ViewBag In View:

MVC Viewbag

The MVC ViewBag property enables you to dynamically share values from the controller to the view. It is a dynamic object which means it has no pre-defined properties. You define the properties you want the ViewBag to have by simply adding them to the property. In the view, you retrieve those values by using same name for the property.

Contact Us| About Us| Terms| Privacy Policies
Powered by Lorquins Technologies© 2017 QuickToStudy.com. All Rights Reserved