How to pass List from Controller to View in MVC 3

后端 未结 4 957
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 15:17

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

4条回答
  •  余生分开走
    2020-12-14 16:07

    You can use the dynamic object ViewBag to pass data from Controllers to Views.

    Add the following to your controller:

    ViewBag.MyList = myList;
    

    Then you can acces it from your view:

    @ViewBag.MyList
    
    // e.g.
    @foreach (var item in ViewBag.MyList) { ... }
    

提交回复
热议问题