标签:
1.首先是创建一个实体:class xxmodel{
public string username{get;set;}
public string articlename{get;set;}
public int articleid{get;set;}
}
2.controller:
public actionresult index(){
var query=from d in user join a in article on d.userid equals a.userid select new xxmodel{
username=d.username,
articlename=a.articlename,
articleid=a.article
};
return view(query.toList());
}
3.view:创建视图
@model IEnumerable<dell.Models.artandcom>
@{
ViewBag.Title = "Index";
}
foreach(var item in model){
<tr>
<td>
@Html.DisplayFor(modelItem => item.username)
</td>
<td>
@Html.DisplayFor(modelItem => item.articlename)
</td>
<td>
@Html.DisplayFor(modelItem => item.articleid)
</td>
</tr>
}
写完收工!!!欢迎大家指正。
标签:
原文地址:http://www.cnblogs.com/xiaow/p/4353404.html