MVC显示列表

首先在控制器要写两个public,一个返回视图,一个返回列表数据

//返回视图

public ActionResult ProductReportList()
        {
           //ViewBag拿值传递给视图页面
            ViewBag.ValidTypes = DictionaryCollectionService.GetDictionaryByTypeForSelectList((int)Enumerator.Dictionary.ValidType);
            ViewBag.FileTypes = 
DictionaryCollectionService.GetDictionaryByTypeForSelectList((int)Enumerator.Dictionary.FileType);
            //返回视图
            return View();
        }
//获取列表数据
 public ActionResult GetProductReportList(SupplierFilePager pager)
        {
            InheritListAuthority(pager);
            pager.StaffId = CurrentUser.GetCurUserInfo.StaffId;
            List<SupplierFileView> viewList = ProductService.GetProductReportList(pager);
            //返回数据
            return Json(new { total = pager.total, rows = viewList },         
                               JsonRequestBehavior.AllowGet);
        }

然后,需要右键ProductReportList,添加视图,在视图页面写上你需要显示出来的东西

然后在服务层,新增一个方法GetProductReportList,上面是查询需要的条件,下面e点出来的就是列表所要显示的,int类型的字段转换成文字

public List<SupplierFileView> GetProductReportList(SupplierFilePager pager)
        {
            if (pager.EndCreateTime != null)
            {
                pager.EndCreateTime = pager.EndCreateTime.Value.AddDays(1);
            }
            List<SupplierFileView> viewList = SupplierFileViewDAL.GetModelsByPage(pager, e => (pager.FileName == null || e.FileName.Contains(pager.FileName))
            && (pager.ValidType == null || e.ValidType == pager.ValidType)
            && (pager.FileType == null || e.FileType == pager.FileType)
            && (pager.StartCreateTime == null || e.ValidityTime >= pager.StartCreateTime)
           && (pager.EndCreateTime == null || e.ValidityTime <= pager.EndCreateTime)
           && (pager.SupplierId == null || e.SupplierId == pager.SupplierId)
           && (string.IsNullOrEmpty(pager.ProductId) || e.ProductId.Contains(pager.ProductId.Trim()))
            && (string.IsNullOrEmpty(pager.SupplierName) || e.SupplierName.Contains(pager.SupplierName.Trim())) 
            );
            DictionaryCollectionService service = DictionaryCollectionService.Instance();
            viewList.ForEach(e => {
                e.ValidTypeDesc = service.GetDictionaryNameByTypeAndDictionaryValue((int)Enumerator.Dictionary.ValidType, e.ValidType);
                e.FileTypeDesc = service.GetDictionaryNameByTypeAndDictionaryValue((int)Enumerator.Dictionary.FileType, e.FileType);
            });
            return viewList;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值