How to pass List from Controller to View in MVC 3

后端 未结 4 948
隐瞒了意图╮
隐瞒了意图╮ 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:00

    Passing data to view is simple as passing object to method. Take a look at Controller.View Method

    protected internal ViewResult View(
        Object model
    )
    

    Something like this

    //controller
    
    List list = new List();
    
    return View(list);
    
    
    //view
    
    @model List
    
    // and property Model is type of List
    
    @foreach(var item in Model)
    {
        @item.Name
    }
    

提交回复
热议问题