首页 > Web开发 > 详细

EF+MVC+Bootstrap 项目实践 Day12

时间:2015-12-21 08:07:49      阅读:280      评论:0      收藏:0      [点我收藏+]

一、分页根据参数取数据

        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", "全部")&nbsp;&nbsp;
                类型:@Html.DropDownList("Category", "全部")&nbsp;&nbsp;
                职业:@Html.DropDownList("Profession", "全部")&nbsp;&nbsp;
                年龄:@Html.DropDownList("AgeGroup", "全部")&nbsp;&nbsp;
                <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、进行搜索

 

EF+MVC+Bootstrap 项目实践 Day12

原文:http://www.cnblogs.com/liuyouying/p/5062384.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!