asp.net-mvc - 如何在控制器中获取数据表的参数?
问题描述
我在视图中使用databale
$("#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"
}
});
我想得到 DoctorId 的aoData
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 或无)时,您应该在输入控制器中有一个变量。您发送数据并且您DoctorId
不在DataTableParameter
课堂上。所以如果你想得到这个参数,你有两个解决方案:
首先是在您的课程中添加 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)
{
???
}
推荐阅读
- mongodb - Realm MongoDB 和 Reanimated 2 之间的冲突
- laravel - Laravel 使用 'With' 子句和 'implode' 将静态参数从模型传递给自身
- android - Firebase 值未更新
- fpga - FPGA Lattice:引脚未连接
- php - 删除重复值节点列表 domdocument PHP
- powerbi - Power BI 比较不同日期的指标
- entity-framework-migrations - 无法加载文件或程序集“启动,Culture=neutral,PublicKeyToken=null”。该系统找不到指定的文件
- javascript - 如何获得路径的所有角落?
- javascript - 如何将 Laravel 中的值导入 react.js
- python - 在 python 中验证 kwargs 中的参数组合