之前調用我有以下代碼。我沒有使用過濾或搜索信息的排序。我也沒有使用skip方法。請參閱下面的代碼。分頁錯誤:「跳過」方法僅支持LINQ to Entities中的排序輸入。方法'OrderBy'必須在方法'Skip'
public ActionResult Index(string currentFilter=null, string search=null, string searchBy=null, int? page=1)
{
var student = from d in db.Student_vw
where d.is_active == true
select d;
if (searchBy == "default")
{
student = student.OrderByDescending(x => x.ID_Number);
}
//searching of an item
if (!String.IsNullOrEmpty(search))
{
student = student.Where(x => x.ID_Number.Contains(search) || x.student_fname.Contains(search)
|| x.student_lname.Contains(search) || x.section_name.Contains(search) || x.course_name.Contains(search)
|| x.student_address.Contains(search) || x.batch_name.Contains(search) || x.adviser_fname.Contains(search) || x.adviser_lname.Contains(search) || x.student_email_add.Contains(search));
}
else {
student = student.OrderByDescending(x => x.ID_Number);
}
ViewBag.CurrentFilter = search;
int pageSize = 25;
int pageNumber = (page ?? 1);
var returnMe = student.ToPagedList(pageNumber, pageSize);
return View(returnMe);
}
在此先感謝您的幫助。
ToPagedList使用跳過,您需要先排序您的結果,如異常消息所述。 –