public ActionResult Index(客戶銀行資訊ViewModel 客戶銀行資訊) { var client = repo.All().Include(x => x.客戶資料); if (!string.IsNullOrEmpty(客戶銀行資訊.搜尋銀行名稱)) { client = repo.FindName(客戶銀行資訊.搜尋銀行名稱, client); } if (!string.IsNullOrEmpty(客戶銀行資訊.sort_col)) { bool sort = 客戶銀行資訊.isSort; if (sort == false) { if (客戶銀行資訊.sort_col == "客戶名稱") { client = (from o in client orderby o.客戶資料.客戶名稱 select o); } else { client = client.OrderByField(客戶銀行資訊.sort_col, true); } } else { if (客戶銀行資訊.sort_col == "客戶名稱") { client = (from o in client orderby o.客戶資料.客戶名稱 descending select o); } else { client = client.OrderByField(客戶銀行資訊.sort_col, false); } } if (ViewBag.isSort != sort) { ViewBag.isSort = sort; } } else { client = client.OrderBy(c => c.Id); ViewBag.isSort = true; } var orderClient = client.ToPagedList(客戶銀行資訊.page == 0 ? 1 : 客戶銀行資訊.page, pageSize); ViewBag.currentPage = 客戶銀行資訊.page == 0 ? 1 : 客戶銀行資訊.page; ViewBag.搜尋銀行名稱 = 客戶銀行資訊.搜尋銀行名稱; return(View(orderClient)); }