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 PagedList.IPagedList<dell.Models.userInfor>
@{
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>
}
<div>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
of @Model.PageCount
@if (Model.HasPreviousPage)
{
@Html.ActionLink("<<", "select", new { page = 1})
@Html.Raw(" ");
@Html.ActionLink("< Prev", "select", new { page = Model.PageNumber - 1})
}
else
{
@:<<
@Html.Raw(" ");
@:< Prev
}
@if (Model.HasNextPage)
{
@Html.ActionLink("Next >", "select", new { page = Model.PageNumber + 1})
@Html.Raw(" ");
@Html.ActionLink(">>", "select", new { page = Model.PageCount })
}
else
{
@:Next >
@Html.Raw(" ")
@:>>
}
</div>
写完收工!!!欢迎大家指正。