I have a List<> binded with some data in Controller action and I want to pass that List<> to View to bind with DataGrid in Razor View.
I am new to MVC.Can any one help me how to pass and how to access in View.
I have a List<> binded with some data in Controller action and I want to pass that List<> to View to bind with DataGrid in Razor View.
I am new to MVC.Can any one help me how to pass and how to access in View.
Create a model which contains your list and other things you need for the view.
For example:
From the action method put your desired list to the Model,
_MyList
property, like:In your view access the model as follows
I think it will help for start.
I did this;
In controller:
In view:
Hope it helps
You can use the dynamic object
ViewBag
to pass data from Controllers to Views.Add the following to your controller:
Then you can acces it from your view:
Passing data to view is simple as passing object to method. Take a look at Controller.View Method
Something like this