其中一个搜索功能,我们的网站会返回一个页面来处理太多的结果,所以我尝试添加由这里提供的分页功能:https://github.com/TroyGoode/PagedList使用PagedList分页功能添加到ASP MVC3网站
该解决方案正确建立和页面加载为好,但是当我试图进行搜索的“NotSupportedException异常”是页面的控制器/索引()方法抛出:
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
Visual Studio 2010和中指向在抛出此异常时返回语句。这只是我在ASP MVC工作的第二天,所以任何建议都是值得欢迎的。谢谢!
case "name":
//if no comma, do a combined search by last name and by corporate name.
searchString = searchString.ToUpper();
var lastAgents =
db.Agent.OrderBy(s => s.LastName).Where(s => s.LastName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification).Include(a => a.SymetraNumberToAgentId);
//end new code
var corp2Agents =
db.Agent.OrderBy(s => s.CorporateName).Where(s => s.CorporateName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification);
if ((corp2Agents.Count() == 0) & (lastAgents.Count() == 0)) ViewBag.ErrorMessage = "None found in search for Last Names and Companies beginning with " + search1;
else ViewBag.Message = "Results of Last Name and Company Name search. Found " + (corp2Agents.Count() + lastAgents.Count()).ToString();
pageNumber = (page ?? 1);
return View(lastAgents.Union(corp2Agents).ToPagedList(pageNumber, pageSize));