其中一個搜索功能,我們的網站會返回一個頁面來處理太多的結果,所以我嘗試添加由這裏提供的分頁功能: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));