只要在data的地方传的参数里有后台EmployeeSearch类里的属性同名就会报这个错误,不解
$.ajax({
  type: 'POST',
  url: p.url,
  data: {PageIndex:1},
  dataType: 'json',
  success: function (data) { g.addData(data); },
  error: function (XMLHttpRequest, textStatus, errorThrown) { document.write(XMLHttpRequest.responseText); }
  });
[HttpPost]
  public JsonResult Employee(EmployeeSearch es)
  {
  System.Data.DataColumn dc = new System.Data.DataColumn();
    
  //int cc=Request.Form.Count;
  Models.Employee emp = new Models.Employee();
  int count = 0;
  ISingleResult<EmployeeGrid> emps = emp.ListBySort("%", new Guid(), 255, "Name DESC", 20, 1, ref count);   
//emp.ListBySort(es.Name, es.Dept, es.Status, es.sortName, es.PageSize, es.PageIndex, ref count);
  if (emp.Msg != null)
  return Json(emp.Msg);
  return Json(new DataGrid(count, emps));
  }

解决方案 »

  1.   

    他报的错误我当然知道是什么意思,问题是我这只传了一个PageIndex,值为1,理论上后台EmployeeSearch类里PageIndex的值就得为1,而不会出现重复的键,其实MVC里会自动将传的参数映射到给定的类里的同名属性,不需要用Request.Form["PageIndex"]来获取,由于没有服务器空间也不存在用this.txtPageIndex.Text来获取,这也是我觉得比webform方便的地方
      

  2.   

    通过反复的测试,发现是继承惹的祸,但不知道该怎么处理EmployeeSearch:GridSearchlinq里的映射,继承好像也有一定问题,不过MSDN上有解决方法,比较繁琐