2017-12-25 3 views
0

I'amに未知パラメータの誤差を求め他の人は、HTMLで私のテーブルの列の定義がサーバーから受け取った列と一致しないと言っています。私の場合はどちらも同じです。はデータテーブルで作業し、このエラー</p> <p>のDataTable警告に対向jQueryのデータテーブルMVC

助けてください!ありがとうございました!

コントローラー:

public IActionResult CompanyProfileView(jQueryDataTableParamModel param) 
    { 
     CompanyProfileModel objCompanyProfileModel = new CompanyProfileModel(); 

     string strResXML = ""; 
     string strErrMsg = ""; 

     try 
     { 
      objCompanyProfileModel.CompanyProfileView(ref strResXML, ref strErrMsg); 
      if (strErrMsg != "") throw (new ApplicationException(strErrMsg)); 

      TextReader sr = new StringReader(strResXML); 
      XElement root = XElement.Load(sr); 

      IEnumerable<XElement> allRecords = 
       from el in root.Elements("RESULT_ROW") 
       select el; 

      IEnumerable<XElement> filteredRecords = allRecords; 

      if (!string.IsNullOrEmpty(param.sSearch)) 
      { 
       filteredRecords = from el in allRecords 
           .Where(el => 
             el.Element("TranID").Value.ToLower().Contains(param.sSearch.ToLower()) || 
             el.Element("CompanyID").Value.ToLower().Contains(param.sSearch.ToLower()) || 
             el.Element("CompanyNm").Value.ToLower().Contains(param.sSearch.ToLower()) || 
             el.Element("CompanySubNm").Value.ToLower().Contains(param.sSearch.ToLower()) || 
             el.Element("CompType").Value.ToLower().Contains(param.sSearch.ToLower())) 
            select el; 
      } 

      var displayedRecords = filteredRecords 
           .Skip(param.iDisplayStart) 
           .Take(param.iDisplayLength); 

      var sortColumnIndex = Convert.ToInt32(Request.Form["iSortCol_0"]); 
      Func<XElement, string> orderingFunction = (c => sortColumnIndex == 0 ? (c.Element("TranID") != null) ? c.Element("TranID").Value.ToString() : "" : 
                  sortColumnIndex == 1 ? (c.Element("CompanyID") != null) ? c.Element("CompanyID").Value.ToString() : "" : 
                  sortColumnIndex == 2 ? (c.Element("CompanyNm") != null) ? c.Element("Purpose").Value.ToString() : "" : 
                  sortColumnIndex == 3 ? (c.Element("CompanySubNm") != null) ? c.Element("CompanySubNm").Value.ToString() : "" : 
                  (c.Element("CompType") != null) ? c.Element("CompType").Value.ToString() : ""); 
      var sortDirection = Request.Form["sSortDir_0"]; // asc or desc 
      if (sortDirection == "asc") 
       displayedRecords = displayedRecords.OrderBy(orderingFunction); 
      else 
       displayedRecords = displayedRecords.OrderByDescending(orderingFunction); 

      var result = from c in displayedRecords 
       select new 
       { 
        TranID = (c.Element("TranID") != null) ? c.Element("TranID").Value.ToString().Trim() : "", 
        CompanyID = (c.Element("CompanyID") != null) ? c.Element("CompanyID").Value.ToString().Trim() : "", 
        CompanyNm = (c.Element("CompanyNm") != null) ? c.Element("CompanyNm").Value.ToString().Trim() : "", 
        CompanySubNm = (c.Element("CompanySubNm") != null) ? c.Element("CompanySubNm").Value.ToString().Trim() : "", 
        CompType = (c.Element("CompType") != null) ? c.Element("CompType").Value.ToString() : "", 
        Action = "Action", 
       }; 



      return Json(new 
      { 
       sEcho = param.sEcho, 
       iTotalRecords = allRecords.Count(), 
       iTotalDisplayRecords = filteredRecords.Count(), 
       aaData = result 
      }); 
     } 
     catch (Exception e) 
     { 
      return Json(new 
      { 
       sMsg = e.Message, 
       sEcho = param.sEcho, 
       iTotalRecords = 0, 
       iTotalDisplayRecords = 0, 
       aaData = "" 
      }); 
     } 
    } 

アヤックス:

$('#DataGridTable').dataTable({ 
     "bServerSide": true, 
     "bProcessing": true, 
     "bFilter": false, 
     "bPaginate": true, 
     "sPaginationType": "full_numbers", 
     "sAjaxSource": "/DataGrid/CompanyProfileView", 
     "fnServerData": function (sSource, aoData, fnCallback) { 
      $.ajax({ 
       "dataType": 'json', 
       "type": "POST", 
       "url": sSource, 
       "data": aoData, 
       "success": fnCallback 
      }); 
     }, 
     "aoColumnDefs" : [ 
      { sTitle : "TRANSACTION ID", sType : "string", mData : "TranID",  aTargets: [0], sClass : 'centered-cell' }, 
      { sTitle : "COMPANY ID",  sType : "string", mData : "CompanyID", aTargets: [1], sClass : 'centered-cell', sDefaultContent: "" }, 
      { sTitle : "COMPANY NAME", sType : "string", mData : "CompanyNm", aTargets: [2], sClass : 'centered-cell', sDefaultContent: "" }, 
      { sTitle : "SUB NAME",  sType : "string", mData : "CompanySubNm", aTargets: [3], sClass : 'centered-cell', sDefaultContent: "" }, 
      { sTitle : "COMPANY TYPE", sType : "string", mData : "CompType",  aTargets: [4], sClass : 'centered-cell', sDefaultContent: "" }, 
      { sTitle : "ACTION",   sType : "string", mData : "Action",  aTargets: [5], sClass : 'centered-cell', sDefaultContent: "" }, 
     ], 
     "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
      $('td:eq(5)', nRow).html('<button class=\"btn btn-primary btn-xs\" ><img src=\"/dist/img/edit.png\" width=\"20px\" height=\"20px\"/></button>&nbsp;<button class=\"btn btn-danger btn-xs\" ><img src=\"/dist/img/delete.png\" width=\"20px\" height=\"20px\"/></button>'); 
     } 
    }); 

HTML:

<table id="DataGridTable" class="display"> 
          <thead> 
           <tr> 
            <th class="gridheader" style="text-align:center">TRANSACTION ID</th> 
            <th class="gridheader" style="text-align:center">COMPANY ID</th> 
            <th class="gridheader" style="text-align:center">COMPANY NAME</th> 
            <th class="gridheader" style="text-align:center">SUB NAME</th> 
            <th class="gridheader" style="text-align:center">COMPANY TYPE</th> 
            <th class="gridheader" style="text-align:center">ACTION</th> 
           </tr> 
          </thead> 
          <tbody></tbody> 
         </table> 

答えて

0

私は、実際の応答をチェックし、私はこれだ:

{ 
"sEcho": "1", 
"iTotalRecords": 2, 
"iTotalDisplayRecords": 2, 
"aaData": [ 
    { 
     "tranID": "1000-12102017-000001", 
     "companyID": "COMP1", 
     "companyNm": "SAMPLE", 
     "companySubNm": "", 
     "compType": "SCHOOL", 
     "action": "Action" 
    }, 
    { 
     "tranID": "1000-12102017-000002", 
     "companyID": "COMP2", 
     "companyNm": "SAMPLE COMPANY", 
     "companySubNm": "", 
     "compType": "COMPANY", 
     "action": "Action" 
    } 
] 

}

...私はちょうどMDATA

mData : "TranID", to mData : "tranID", 

を変更し、それが動作します

関連する問題