标签:
方法一
//controller public IActionResult list(){ var objects=new List<Object>(); for(int i=0;i<=10;i++){ objects.Add(new Object{Title="xxxx"+i}); } ViewBag.Objects=objects; return view(objects); } //view <ul> @foreach(Object a in(Viewbag.Objects as IEnumeranle<Object>)){ <li>@a.title</li>
} </ul>
方法二
//controller
public IActionResult list(){
var objects = new List<Object>();
for(int i=0;i<=10;i++){
objects.Add(new Object{Title="xxxx"+i});
}
viewBag.Objects=objects;
return View();
}
//view
<ul>
@foreach(dynamic a ViewBag.Objects){
<li>@a.Title</li>
}
<ul/>
方法三
//controller
public IActionResult list(){
var objects = new List<>(Object);
for(int i = 0;i<=10;i++){
objects.Add(new Object{Title="xxxx"+i});
}
return view(objects);
}
//view
//using MyApplication.Models
//@model IEnumerable<Object>
@model IEnumerable<MyApplication.Models.Object>
<ul>
@foreach(Object a in model){
<li>@a.Title</li>
}
视图模型(xxxxxViewModels):专门为视图提供信息的模型。不同于MVVM模式中的视图模型。
标签:
原文地址:http://www.cnblogs.com/dagedan/p/5509668.html