Why doesn't the search for ASP MVC JSON?



  • There's a controller, that's the type that sends JSON.

    [HttpPost]
            public ActionResult LoadDataFromAD()
            {
    
            //Get parameters
            var v = ActiveDirectory.GetUserFromAD();
            // get Start (paging start index) and length (page size for paging)
            var draw = Request.Form.GetValues("draw").FirstOrDefault();
            var start = Request.Form.GetValues("start").FirstOrDefault();
            var length = Request.Form.GetValues("length").FirstOrDefault();
            //Get Sort columns value
            var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
    
            //find search columns info
            var contactName = Request.Form.GetValues("columns[0][search][value]").FirstOrDefault();
    
    
            //SEARCHING...
            if (!string.IsNullOrEmpty(contactName))
            {
                v = v.Where(a => a.DisplayName.Contains(contactName));
            }
    
    
            int pageSize = length != null ? Convert.ToInt32(length) : 0;
            int skip = start != null ? Convert.ToInt32(start) : 0;
            int totalRecords = 0;
    
    
            totalRecords = v.Count();
    
            var data = v.Skip(skip).Take(pageSize).ToList();
            return Json(new { draw = draw, recordsFiltered = totalRecords, recordsTotal = totalRecords, data = data }, JsonRequestBehavior.AllowGet);
        }
    

    Data are correctly transmitted to AC contactName.

    //SEARCHING...
    if (!string.IsNullOrEmpty(contactName))
    {
    v = v.Where(a => a.DisplayName.Contains(contactName));
    }

    The error arises when searching

    введите сюда описание изображения

    I don't know when I write Contains like that.

     v = v.Where(a => a.DisplayName==contactName);

    And I'm putting in a full line to search the table, everything works on the corner. Help!



  • Structural variables may be important null♪ Add the check:

    a.DisplayName != null && aDisplayName.Contains(...
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2