What is ViewBag?

ViewBag is an object which is dynamically passing the data from Controller to View and this will pass the data as the property of object ViewBag. We do not need to typecast to read the data for null checking here.

Controller:

 

 

View:

 

 

Here is an example:

Controller:

 

 

View:

 

×