[英]How to invoke ajax call in jQuery DataTable using ASP.NET MVC
我暫時使用了jQuery DataTables 1.10.13插件。 我偶然發現了與html表的ajax數據源相關的問題。
Files.cshtml中的jQuery DataTable初始化
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var oTable = $("#tblFile").DataTable({
"iDisplayLength": 10,
"bServerSide": true,
"sAjaxSource": "@Url.Content("PlayListFilesAjaxHandler")" + "?playListId=" + getParameter(),
"bProcessing": true,
"bStateSave": true,
"aoColumns": [
{
"sName": "FileName",
"bSearchable": true,
"bSortable": true,
"sWidth": '25%'
},
{
"sName": "FilePath",
"bSearchable": true,
"bSortable": true,
"sWidth": '50%'
},
{
"sName": "Order",
"bSearchable": true,
"bSortable": true,
"sWidth": '10%'
},
{
"sName": "Action",
"bSearchable": false,
"bSortable": false,
"sWidth": '15%',
"render": function (data, type, full, meta) {
return '<a class="btn btn-primary deleteButton" href=\"FileDelete/' + full[3] + '\">Delete</a>';
}
}
]
});
});
我想知道這是否是使用參數調用ajax請求的正確方法? 因為,在調用“文件”操作結果之后,不會觸發PlayListFilesAjaxHandler方法。
"sAjaxSource": "@Url.Content("PlayListFilesAjaxHandler")" + "?playListId=" + getParameter(),
這是home控制器類內部的FileAction操作結果方法和PlayListFilesAjaxHandler的參數
[Authorize]
public ActionResult Files()
{
return View();
}
public ActionResult PlayListFilesAjaxHandler(string playListId, JQueryDataTableParamModel param)
{ ... }
這是html表的結構
<table id="tblFile" class="table table-responsive">
<thead>
<tr>
<th>
File Name
</th>
<th>
File Path
</th>
<th>
Sequence
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody></tbody></table>
任何幫助是極大的贊賞。
如果您未使用api控制器,請嘗試返回json結果。
公共JsonResult PlayListFilesAjaxHandler(string playListId,JQueryDataTableParamModel param){
返回Json(IEnumerable);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.