[英]How to invoke ajax call in jQuery DataTable using ASP.NET MVC
I'm using jQuery DataTables 1.10.13 plugin for awhile now. 我暂时使用了jQuery DataTables 1.10.13插件。 I have stumbled upon this issue which is related with ajax data source for my html table.
我偶然发现了与html表的ajax数据源相关的问题。
jQuery DataTable initialization inside Files.cshtml 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>';
}
}
]
});
});
I wondered if this is the correct way of calling ajax request with a parameter? 我想知道这是否是使用参数调用ajax请求的正确方法? Because, the PlayListFilesAjaxHandler method is not triggered after Files action result is invoked.
因为,在调用“文件”操作结果之后,不会触发PlayListFilesAjaxHandler方法。
"sAjaxSource": "@Url.Content("PlayListFilesAjaxHandler")" + "?playListId=" + getParameter(),
This is the Files action result method and parameters of PlayListFilesAjaxHandler inside the home controller class 这是home控制器类内部的FileAction操作结果方法和PlayListFilesAjaxHandler的参数
[Authorize]
public ActionResult Files()
{
return View();
}
public ActionResult PlayListFilesAjaxHandler(string playListId, JQueryDataTableParamModel param)
{ ... }
This is the structure of html table 这是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>
Any help is greatly appreciated. 任何帮助是极大的赞赏。
if you didn't use api controller, try to return with json result. 如果您未使用api控制器,请尝试返回json结果。
public JsonResult PlayListFilesAjaxHandler(string playListId,JQueryDataTableParamModel param) { 公共JsonResult PlayListFilesAjaxHandler(string playListId,JQueryDataTableParamModel param){
return Json(IEnumerable); 返回Json(IEnumerable);
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.