public ActionResult Index(客戶聯絡人ViewModel 客戶聯絡人) { var client = repo.All().Include(x => x.客戶資料); if (!string.IsNullOrEmpty(客戶聯絡人.搜尋姓名)) { client = repo.FindName(客戶聯絡人.搜尋姓名, client); } if (!string.IsNullOrEmpty(客戶聯絡人.篩選職稱)) { client = repo.GetPosition(客戶聯絡人.篩選職稱, 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.ToString(); ViewBag.搜尋姓名 = 客戶聯絡人.搜尋姓名; ViewBag.篩選職稱 = 客戶聯絡人.篩選職稱; ViewBag.職稱 = GetPositionSelect(); return(View(orderClient)); }