如何在控制器中获取数据表的参数?

How to get param of datatable in controller?

我在视图中使用数据表

   $("#table-DoctorClosure").DataTable({
            "bServerSide": true,
            "sAjaxSource": "@Url.Action("PaginationList", "DoctorClosure")",
            "fnServerData": function (sSource, aoData, fnCallback) {
                aoData.push({ "name": "DoctorId", "value": @ViewBag.doctorId} );
                $.ajax({
                    type: "Get",
                    data: aoData,
                    url: sSource,
                    success: fnCallback
                })
            },
            "aoColumns": [
                { "mData": "Date" },
                { "mData": "Description" },
                {
                    "mData": "Id",
                    "className": "text-center ",
                    "render": function(Id, type, full, meta) {
                        return '<a class="btn-edit  btn btn-warning btn-sm m-l-5" href="/Doctor/DoctorClosure/Edit?id=' + Id +'" data-toggle="tooltip" data-placement="top" title="@OperationResource.Edit"><i class="icon-pencil" ></i> </a>' +
                            '<a class="btn-delete btn btn-sm bg-danger"  data-id="'+Id+'" data-toggle="tooltip" data-placement="top" title="@OperationResource.Delete"><i class="icon-trash-o"></i> </a>'
                    }
                },
            ],
            "oLanguage": {
                "sUrl": "/Content/styles/datatables/dataTables.persian.txt"
            }
        });

我想获得 aoData

的 DoctorAte
  public async Task<ActionResult> PaginationList(DataTableParameter param)
  {
   ???
  }

DataTableParameter

 public  class DataTableParameter
{
    /// <summary>
    /// Request sequence number sent by DataTable,
    /// same value must be returned in response
    /// </summary>
    public string sEcho { get; set; }
    /// <summary>
    /// Text used for filtering
    /// </summary>
    public string sSearch { get; set; }
    /// <summary>
    /// Number of records that should be shown in table
    /// </summary>
    public int iDisplayLength { get; set; }
    /// <summary>
    /// First record that should be shown(used for paging)
    /// </summary>
    public int iDisplayStart { get; set; }
    /// <summary>
    /// Number of columns in table
    /// </summary>
    public int iColumns { get; set; }
    /// <summary>
    /// Number of columns that are used in sorting
    /// /// </summary>
    public int iSortingCols { get; set; }
    /// <summary>
    /// Comma separated list of column names
    /// </summary>
    public string sColumns { get; set; }
}

如果我正确理解你的问题,当你向控制器发送数据时(使用 ajax 或 none)你应该在输入控制器中有一个变量。 您发送数据,但您的 DoctorId 不在 DataTableParameter class 中。所以如果你想得到这个参数,你有两个解决方案:

首先是在您的 class 中添加 DoctorId(或使用此参数创建视图模型):

 public  class DataTableParameter
{
    /// <summary>
    /// Request sequence number sent by DataTable,
    /// same value must be returned in response
    /// </summary>
    public string sEcho { get; set; }
    /// <summary>
    /// Text used for filtering
    /// </summary>
    public string sSearch { get; set; }
    /// <summary>
    /// Number of records that should be shown in table
    /// </summary>
    public int iDisplayLength { get; set; }
    /// <summary>
    /// First record that should be shown(used for paging)
    /// </summary>
    public int iDisplayStart { get; set; }
    /// <summary>
    /// Number of columns in table
    /// </summary>
    public int iColumns { get; set; }
    /// <summary>
    /// Number of columns that are used in sorting
    /// /// </summary>
    public int iSortingCols { get; set; }
    /// <summary>
    /// Comma separated list of column names
    /// </summary>
    public string sColumns { get; set; }

    /// <summary>
    /// if you use this you can send and use it in controller
    /// </summary>
    public int DoctorId { get; set; }
}

第二种方法是在控制器输入中添加另一个参数:

public async Task<ActionResult> PaginationList(DataTableParameter param, int DoctorId)
  {
   ???
  }