【发布时间】:2017-01-13 12:19:39
【问题描述】:
我的部分视图如下:
@model IPagedList<Student>
<h2>List of Students</h2>
<div id="studentList">
<div class="pagedList" data-uwa-target="#studentList">
@Html.PagedListPager(Model,page=>Url.Action("Index",new { page }),
PagedListRenderOptions.MinimalWithItemCountText)
</div>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.LastName) //here error
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName) //here error
</th>
<th>
@Html.DisplayNameFor(model => model.City) //here error
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
</tr>
}
</table>
<div class="row">
<div class="col-sm-6" id="slid">
<button id="export" class="btn btn-default btn-primary" onclick="location.href='@Url.Action("ExportInCSVFormat")';return false;">Export Student List in CSV Format</button>
</div>
<div class="col-sm-4" id="excelSlide">
<button id="excelExport" class="btn btn-default btn-success" onclick="location.href='@Url.Action("ExportStudentsInExel")';return false;">Export Student List in Excel Format</button>
</div>
</div>
我的 Index.cshmtl 是:
@model IPagedList<Student>
@{
ViewBag.Title = "Index";
}
@Html.Partial("_Student", Model)
我的 StudentController 是
public ActionResult Index(int page=1)
{
var model = dbAllStudents.Students
.OrderByDescending(p => p.LastName)
.ToPagedList(page, 10);
return View(model);
}
问题发生在“@Html.DisplayNameFor(model => model.LastName)”上。它是说“ IPaged 不包含 LastName 的定义。
我知道问题是由于学生控制器的 Index 方法引起的,我需要添加 .Select 但我不确定。如果有人可以帮助我,我将不胜感激
【问题讨论】:
标签: c# asp.net-mvc pagedlist