-->

Thursday, December 10, 2015

How to pass data from controller to view in ASP.NET MVC

How to pass data from controller to view in ASP.NET MVC

If you want to pass value from controller to view in asp.net MVC, we have two methods. The first method of it is ViewBag and last is ViewData, both are used to pass data from controller to view. ViewBag object creates a dynamic variable and ViewData creates a dynamic key like ViewState in ASP.NET.  Learn, How to use ViewBag in MVC for single variable as well as List<String> type variable. 


In controller class, we used ViewBag.Dynamic_variable = "Value" and in View we used @ViewBag.Dynamic_Variable_Name. Also, learn how to pass value from controller to view using ViewData.



Both objects doesnot generate compile time error.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved