如何使用ASP.NET MVC在jQuery DataTable中调用Ajax调用 [英] How to invoke ajax call in jQuery DataTable using ASP.NET MVC
问题描述
我暂时正在使用jQuery DataTables 1.10.13插件.我偶然发现了这个问题,该问题与我的html表的ajax数据源有关.
I'm using jQuery DataTables 1.10.13 plugin for awhile now. I have stumbled upon this issue which is related with ajax data source for my html table.
Files.cshtml中的jQuery DataTable初始化
jQuery DataTable initialization inside Files.cshtml
<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请求的正确方法? 因为,调用Files操作结果后,不会触发PlayListFilesAjaxHandler方法.
I wondered if this is the correct way of calling ajax request with a parameter? Because, the PlayListFilesAjaxHandler method is not triggered after Files action result is invoked.
"sAjaxSource": "@Url.Content("PlayListFilesAjaxHandler")" + "?playListId=" + getParameter(),
这是家庭控制器类中PlayListFilesAjaxHandler的文件"操作结果方法和参数
This is the Files action result method and parameters of PlayListFilesAjaxHandler inside the home controller class
[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结果.
if you didn't use api controller, try to return with json result.
公共JsonResult PlayListFilesAjaxHandler(字符串playListId,JQueryDataTableParamModel参数) {
public JsonResult PlayListFilesAjaxHandler(string playListId,JQueryDataTableParamModel param) {
返回Json(IEnumerable);
return Json(IEnumerable);
}
这篇关于如何使用ASP.NET MVC在jQuery DataTable中调用Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!