У меня есть этот частичный вид, как показано ниже:PagedList <T> не содержит определение для свойств моей модели <T>
@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 для студенческого контроллера мне нужно добавить. Выберите, но я не уверен в этом. был бы очень рад, если кто-то может мне помочь