【发布时间】:2014-04-01 14:43:12
【问题描述】:
我正在学习 MVC 中的分页
在索引视图中我有搜索按钮,它应该显示结果分页明智
Home 控制器中的索引方法 ...
public ActionResult Index(string searchBy, string search ,int? Page)
{
if (searchBy == "Gender")
{
return View(db.Employees.Where(x => x.Gender == search || search == null).ToList().ToPagedList(Page??1,3)) ;
}
else
{
return View(db.Employees.Where(x => x.FUllName == search || search == null).ToList());
}
}
和索引视图
@using PagedList;
@using PagedList.Mvc;
@model IPagedList<_SearchDemo.Models.Employee>
<p>
@using (Html.BeginForm("Index","Home",FormMethod.Get))
{
<b>SearchBy</b> @Html.RadioButton("searchBy", "Name", true)
<text>Name</text>
@Html.RadioButton("searchBy", "Gender") <text>Gender</text>
<br />
@Html.TextBox("search") <input type="submit" value="search" />
}
</p>
<table border="1">
<tr>
<th>
@Html.DisplayNameFor(model => model.First().FUllName)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.FUllName)
</td>
</tr>
}
</table>
在重新加载索引页面时出现错误...
传入字典的模型项是类型 'System.Collections.Generic.List
, but this dictionary requires a model item of type 'PagedList.IPagedList1
【问题讨论】:
-
你为什么不仔细看看错误信息,然后看看那两条
return View...行,我敢打赌你自己就能找到答案。 -
StackOverflow 会在您完成自己可以做的所有事情时为您提供帮助,而不是在您遇到错误时作为您的第一站。特别是这个错误是少数非常具体说明问题所在的错误之一,我相信如果你花点时间,你可以很容易地自己弄清楚。
标签: asp.net-mvc asp.net-mvc-4 razor