• How to pass data from Controller to View in ASP.NET MVC

    by  • December 17, 2015 • Microsoft ASP.NET MVC • 0 Comments

    In this article, I will tell , how can we pass data from Controller to View. To pass data from controller to view in ASP.NET MVC ,we use View Bag and View data.

    ViewBag uses the dynamic feature as it allows the object to have properties dynamically added.

    ViewBag.YourProperty = “SomeData”;

    ViewData is a dictionary of Objects that are stored and retrieved using strings as Keys.

    ViewData[“YourKey”] = “SomeData”;

    Now with the  following code i will  illustrate ViewData.

    FruitsController.cs  (Controller)

    Index.cshtml (View)

     

     




    Namecheap.com

    Leave a Reply