How to pass List from Controller to View in MVC 3

The Solution to How to pass List from Controller to View in MVC 3 is


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<MyObject> list = new List<MyObject>();

return View(list);


//view

@model List<MyObject>

// and property Model is type of List<MyObject>

@foreach(var item in Model)
{
    <span>@item.Name</span>
}

~ Answered on 2012-06-12 10:36:23


Most Viewed Questions: