//控制器
public ActionResult Index()
{
var People = new List<Customer>
{
new Customer { Name = "Customer 1" },
new Customer { Name = "Customer 2"}
};
return View(People);
}
//查看
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
@foreach(人中的可变项)
<p>@item</p>
///我对View感到困惑。我尝试了所有不同的选项,包括Youtube和堆栈溢出,但似乎不起作用。
答案 0 :(得分:0)
您将可以使用此代码显示数据
public ActionResult Index()
{
var people = new List<Customer>()
{
new Customer{Name = "kamasdfsaol"},
new Customer{Name = "susuasdfsa"}
};
return View(people);
}
您的视图应如下所示
@model IEnumerable<Customer>
@foreach (var item in Model) {
@item.Name <br/>
}