top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is difference between ViewData and ViewBag in ASP.NET MVC?

+1 vote
447 views
What is difference between ViewData and ViewBag in ASP.NET MVC?
posted Sep 1, 2016 by Sathaybama

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

-ViewData is a dictionary object in which we can store the data. The data then will be accessed from the view.

-ViewData is derived from the ViewDataDictionary class and we can use the traditional "key-value" syntax.

-The ViewBag object act as a wrapper around the ViewData object.

-By using ViewBag we can create dynamic properties for the ViewBag.

-For example

ViewData["product"] = product; // Syntax of ViewData
ViewBag. product = product; // Syntax of ViewBag
answer Sep 1, 2016 by Shivaranjini
...