public class MyModel
{
public List MyList { get; set; }
}
public class MyController : Controller
{
public ActionResult MyAction()
{
var model = new MyModel();
model.MyList = new List { "item1", "item2", "item3" };
return View(model);
}
}
@model MyModel
@foreach(var item in Model.MyList)
{
- @item
}
这样,列表就被嵌入在模型中,并可以在视图中使用它。