ASP.NET MVC - ViewBag

 

    In ASP.NET MVC, the ViewBag is used to send temporary data from the controller to the view that isn't contained in the model.

       It is a dynamic type property of the ControllerBase class, which is the Controller class's base class.

    ViewBag can have any number of properties and values. If you assign the same property name to ViewBag numerous times, it will only take into account the most recent value assigned to the property. 

    ViewBag only transfers data from controller to view, not visa-versa. ViewBag values will be null if redirection occurs. 

ViewBag Limitations

·        When obtaining values from ViewBag, you don't need to typecast. If the improper method is used on the value, a run-time exception will be thrown. 
·        Because ViewBag is a dynamic type, compile-time verification is not performed. As a result, when manually writing ViewBag properties, they must match in both the controller and the view.

Comments

Popular posts from this blog

SLACK

Scrum