1、返回一个数据集方法:
Controller页:
var list=db.users.ToList(); return View(list);
View页:
@model IEnumerable<myMVC.Models.User> @foreach(var item in Model) { @item.Name }
2、返回多个数据集方法:
Model页:
public class IndexMoel { public List<UserGroup> UserGroup{get;set;} public List<User> User{get;set;} ……
}
Controller页:
var list=new IndexModel(); list.UserGroup=db.UserGroups.ToList(); list.User=db.User.ToList(); return View(list);
View页面:
@model myMvc.IndexModel @foreach(var g in Model.UseGroup) { @g.GroupName } @foreach(var u in Model.User) { @u.UserName }