一、分页根据参数取数据
public ActionResult Index() { var queryList = new CrmEntities().Customer; int pageIndex = Convert.ToInt16(Request["pageIndex"]); PagedList<Customer> customerPageList=queryList.OrderByDescending(x => x.ID).ToPagedList(pageIndex, 10); return View(customerPageList); }
点击分页会传pageIndex=页数,其它都封装好了,直接就可以用了
二、搜索栏
1、基本样式
基本的样式出来了,其中下拉框的值要处理一下
<div> 性别:@Html.DropDownList("Gender", "全部") 类型:@Html.DropDownList("Category", "全部") 职业:@Html.DropDownList("Profession", "全部") 年龄:@Html.DropDownList("AgeGroup", "全部") <button type="submit" class="btn">搜索</button> </div>
public ActionResult Index() { //分页 var customerDbSet = new CrmEntities().Customer; int pageIndex = Convert.ToInt16(Request["pageIndex"]); PagedList<Customer> customerPageList = customerDbSet.OrderByDescending(x => x.ID).ToPagedList(pageIndex, 10); //下拉框 Customer customer=new Customer(); ViewData.Add("Gender", new SelectList(EnumHelper.GetItemValueList<CrmEnum.EnumGender>(), "Key", "Value", customer.Gender)); ViewData.Add("Category", new SelectList(EnumHelper.GetItemValueList<CrmEnum.EnumCategory>(), "Key", "Value", customer.Category)); ViewData.Add("Profession", new SelectList(EnumHelper.GetItemValueList<CrmEnum.EnumProfession>(), "Key", "Value", customer.Profession)); ViewData.Add("AgeGroup", new SelectList(EnumHelper.GetItemValueList<CrmEnum.EnumAgeGroup>(), "Key", "Value", customer.AgeGroup)); return View(customerPageList); }
2、进行搜索
原文:http://www.cnblogs.com/liuyouying/p/5062384.html