简体   繁体   English

数据表警告:表 id=DimStatus - 初始化数据表时,第 0 行第 0 列请求未知参数“代码”

[英]DataTables warning: table id=DimStatus - Requested unknown parameter 'Code' for row 0, column 0,when initialize datatable

I want to show my data in datatable but I get the above error.我想在数据表中显示我的数据,但出现上述错误。 My Table Property:我的表属性:

 [Table("DimStatus", Schema = "dmg")]
  public class PolicyState
   {
      [Key]
      public int Code { get; set; }
      public string Title { get; set; }
   }

My Api: [Route("api/[controller]/[action]")] [ApiController] public class ReportController: Controller { private ICommonServices _CommonService;我的 Api: [Route("api/[controller]/[action]")] [ApiController] public class ReportController: Controller { private ICommonServices;

    public ReportController(ICommonServices CommonService)
    {
        _CommonService = CommonService;

    }
     //  GET
    public IActionResult Index()
    {
        return View();
    }


    [HttpPost]
    public IActionResult GetPolicyState()
    {
        try
        {
            var draw = Request.Form["draw"].FirstOrDefault();
            var start = Request.Form["start"].FirstOrDefault();
            var length = Request.Form["length"].FirstOrDefault();
            var sortColumn = Request.Form["columns[" + Request.Form["order[0] 
                                         [column]"].FirstOrDefault() +
                                          "][name]"].FirstOrDefault();
            var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();
            var searchValue = Request.Form["search[value]"].FirstOrDefault();
            int pageSize = length != null ? Convert.ToInt32(length) : 0;
            int skip = start != null ? Convert.ToInt32(start) : 0;
            int recordsTotal = 0;
             var PolicyData = (from tempcustomer in _CommonService.GetPolicyState() select tempcustomer);
            //var PolicyData = _CommonService.GetPolicyState();

            if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection)))
            {
                PolicyData = PolicyData.OrderBy(sortColumn + " " + sortColumnDirection);
            }

            if (!string.IsNullOrEmpty(searchValue))
            {
                PolicyData = PolicyData.Where(m => m.Title.Contains(searchValue));

            }
            recordsTotal = PolicyData.Count();
            var data = PolicyData.Skip(skip).Take(pageSize).ToList();
            var jsonData = new
            {
                draw = draw,
                recordsFiltered = recordsTotal,
                recordsTotal = recordsTotal,
                data = data
            };

            var testd = jsonData;
            return Ok(jsonData);
        }
        catch (Exception ex)
        {
            throw;
        }
    }
}

and last my index.cshtml:最后是我的 index.cshtml:

    <link rel="stylesheet" type="text/css" 
    href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.css">

<div class="container">
<br />
<div style="width:90%; margin:0 auto;">
    <table id="DimStatus" class="table table-striped table-bordered dt-responsive nowrap"
           width="100%" cellspacing="0">
        <thead>
            <tr>
                <th>Code</th>
                <th>Title</th>
                <th>asdf</th>

               </tr>
           </thead>
       </table>
    </div>
</div>
 @section Scripts
  {
  <script type="text/javascript" charset="utf8" 
 src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.js"></script>
  <script>
    $(document).ready(function () {
            dataTable = $('#DimStatus').dataTable({
            serverSide: true,
            processing: true,
            //searchDelay: 500,
            pageLength: 10,
            infoFiltered: true,
            orderMulti: false,
            "ajax": {
                "url": "/api/Report/GetPolicyState",
                "type": "POST",
                "datatype": "json"
            },

            "columns": [
                { "data": "Code", "name": "Code", "autoWidth": true },
                { "data": "Title", "name": "Title", "autoWidth": true },
                {
                    "render": function (data, row) {
                        return "<a href='#' class='btn btn-danger' onclick=DeleteCustomer('" + 
               row.Code + "'); >Details</a>";
                    }

                },

                ]
        });
    });
would if anybody know the issue help me solve it. 如果有人知道这个问题会帮助我解决它。 thank you in advanced. 谢谢你。

Your error clearly states that your returning data does not have any property name "Code".您的错误清楚地表明您返回的数据没有任何属性名称“代码”。 Make sure that the data structure your are returning contains property name "Code" as you are processing on PolicyData class and not PolicyState class that you have showed in the sample code.确保您返回的数据结构包含属性名称“代码”,因为您正在处理PolicyData class 而不是您在示例代码中显示的PolicyState class。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据表显示:DataTables 警告:表 id=userdetails - 为第 0 行、第 1 列请求未知参数“1” - Datatable showing :DataTables warning: table id=userdetails - Requested unknown parameter '1' for row 0, column 1 DataTables警告:table id = example - 第1行第1列请求的未知参数“1” - DataTables warning: table id=example - Requested unknown parameter '1' for row 1, column 1 DataTables警告:表ID = table_especie-请求的未知参数&#39;0&#39;,用于第0行第0列 - DataTables warning: table id=table_especie - Requested unknown parameter '0' for row 0, column 0 数据表警告:表 id={id} - 为行 {row-index}、column{column-index}` 请求未知参数“{parameter}” - DataTables warning: table id={id} - Requested unknown parameter '{parameter}' for row {row-index}, column{column-index}` 数据表警告:表 id=<my_table_name> - 请求未知参数&#39;<my_table_first_column_name> &#39; 表示第 0 行,第 0 列 - DataTables warning: table id=<my_table_name> - Requested unknown parameter '<my_table_first_column_name>' for row 0, column 0 DataTables警告(表ID =“示例”):从数据源请求的第0行的未知参数“ 0” - DataTables warning (table id = 'example'): Requested unknown parameter '0' from the data source for row 0 数据表错误:第0行第10列请求的未知参数&#39;10&#39;; 尝试将复选框添加到数据表时 - Datatables error: Requested unknown parameter '10' for row 0, column 10; when tried to add checkbox to the datatable jQuery Datatables请求行&#39;0&#39;列&#39;0&#39;的未知参数&#39;0&#39; - jQuery Datatables Requested unknown parameter '0' for row '0' column '0' 数据表-第0行第0列的请求的未知参数&#39;0&#39; - Datatables - Requested unknown parameter '0' for row 0, column 0 DataTables警告-为第0行第0列请求未知参数&#39;0&#39; - DataTables warning - Request unknown parameter '0' for row 0, column 0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM