MVC Developer Question:

Tell us what are the Difference between ViewBag&ViewData?

Tweet Share WhatsApp

Answer:

☛ ViewData is a dictionary of objects that is derived from ViewDataDictionary class and accessible using strings as keys.
☛ ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.

☛ ViewData requires typecasting for complex data type and check for null values to avoid error.
☛ ViewBag doesn't require typecasting for complex data type.

Calling of ViewBag is:
ViewBag.Name = "Hasan";

Calling of ViewData is :
ViewData["Name"] = " Hasan ";

Download MVC Developer PDF Read All 50 MVC Developer Questions
Previous QuestionNext Question
Suppose if we have multiple filters, what’s the sequence for execution?Tell us what is display mode in MVC?