值不能为null(绘制数据)

时间:2018-05-01 22:06:47

标签: c# asp.net-mvc datatables

我使用Datatable来显示一些数据并使用排序和分页选项...它非常好用,当我尝试添加filtring(Datemin和DateMax)时,我得到了上面的错误并且&# 39; s指向var draw = Request.Form.GetValues("draw").FirstOrDefault();

这是我在我的控制器中使用的方法(在添加日期之前)将数据发送到我的视图:

[HttpPost]
        public ActionResult GetList()
        {
            List<Réception_trains> listconsom = new List<Réception_trains>();

从这里发生错误

var draw = Request.Form.GetValues("draw").FirstOrDefault();
            var start = Request.Form.GetValues("start").FirstOrDefault();
            var length = Request.Form.GetValues("length").FirstOrDefault();
            //Find Order Column
            var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();       
            int pageSize = length != null ? Convert.ToInt32(length) : 0;
            int skip = start != null ? Convert.ToInt32(start) : 0;
            int recordsTotal = 0;

            db.Configuration.LazyLoadingEnabled = false;

            var list = db.Réception_trains.Where(y =>( y.Supprimée != true)).
                Select(x => new
                {
                    Id_rec = x.Id_rec,
                    N_Train = x.N_Train,
                    Date_rec = x.Date_rec.ToString(),
                    heure_rec = x.heure_rec,

                    Qualité = x.Qualité.Qualité1,

                    Poids = x.Wagons.AsEnumerable().Where(y => y.Id_rec == x.Id_rec).Select(w => (w.Poids - 15900)).Sum(),
                    Nbwg =x.Wagons.Where(y => y.Id_rec == x.Id_rec).Count()

        });

            //SORT
            if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
            {
                list = list.OrderBy(sortColumn + " " + sortColumnDir);
            }

            recordsTotal = list.Count();


            var data = list.Skip(skip).Take(pageSize).ToList();
            return Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }, JsonRequestBehavior.AllowGet);
        }

当我添加这样的日期时:

 [HttpPost]
        public ActionResult GetList(DateTime? Datemin=null,DateTime? DateMax=null)
        {//same codes}

使用此代码从View中调用它:

 <form action="/Réception_trains/GetList"method='post'>

   <input type="date" name="Datemin" id="datePicker" >
   <input type="date" name="DateMax" id="datePicker" >
   <input type="submit" value="MAJ">              

                </form>

我收到了错误。

0 个答案:

没有答案