ASP.NET CORE 3 frombody NULL 与 Bootstrap Table 插件

问题描述

我正在尝试根据引导表中的这个示例进行操作 query params。但是我收到的参数总是NULL,即使我在调用后端之前已经设置了它。我希望收到的价值应该是供应商。谢谢

查看

<table id="supplier-inBox-table" class="table table-bordered table-striped text-center bootstrap-table"
   data-toggle="table"
   data-query-params="InBoxTableParams"
   data-url="/AppService/Get_InBoxTableData"
   data-method="post"
   data-pagination="true"
   data-side-pagination="server">
<thead class="thead-dark">
    <tr>
        <th data-checkBox="true"></th>
        <th data-field="ID" data-sortable="true">ID No</th>
        <th data-field="Customer" data-sortable="true">Customer</th>
        <th data-field="StoreCode" data-sortable="true">Store Code</th>
    </tr>
</thead>
<script>
function InBoxTableParams(params) {
  params.UserType = 'supplier';

  return params;
}
</script>

控制器

[HttpPost]
public string Get_InBoxTableData([FromBody] InBoxTableData inBoxData)
{
  return inBoxData.UserType;
}

模型

public class InBoxTableData
{
    public string UserType { get; set; }
}

解决方法

当你调用Get_InboxTableData时,你会得到三个参数,UserType,offset and limit。所以你可以尝试使用

public class InboxTableData
    {
        public string UserType { get; set; }
        public int limit { get; set; }
        public int offset { get; set; }

    }

结果: enter image description here