public ActionResult Index(string sortOrder, string 客戶分類 = "", int page = 1) { // 測試多國語系 - .Net程式依語系取得資源內容 - 在 Controller/Action 套用多國屬性設定值 ViewBag.Query = App_GlobalResources.Resource.Query; int currentPage = page < 1 ? 1 : page; IQueryable <客戶資料> data = null; if (string.IsNullOrEmpty(客戶分類)) { data = repo.Get列表所有客戶資料(); } else { data = repo.Get列表所有客戶資料() .Where(c => c.客戶分類.ToUpper() == 客戶分類.ToUpper()); } // *** 實作排序功能(點選同一欄位切換下一次搜尋條件,回傳給 View 紀錄下來) Begin *** // 先實作2個欄位排序:客戶名稱 & 統一編號 ViewBag.CNameSortParm = String.IsNullOrEmpty(sortOrder) ? "cname_desc" : ""; ViewBag.CNumberSortParm = sortOrder == "cnumber" ? "cnumber_desc" : "cnumber"; switch (sortOrder) { case "cname_desc": data = data.OrderByDescending(c => c.客戶名稱); break; case "cnumber": data = data.OrderBy(c => c.統一編號); break; case "cnumber_desc": data = data.OrderByDescending(c => c.統一編號); break; default: data = data.OrderBy(c => c.客戶名稱); break; } // *** 實作排序功能(點選同一欄位切換下一次搜尋條件,回傳給 View 紀錄下來) Begin *** //return View(data.ToList()); var result = data.ToPagedList(currentPage, pageSize); return(View(result)); }