我在想是否可以在数据表中使用 Ajax.reload() 将不同的参数传递给 Controller 。
感谢 stackoverflow 上的另一个主题,我能够将参数从我的变量传递到 url.Action on create the table new { cyfy = "_Switch"})".replace("_Switch",Switch )
然后单击按钮,我更改变量的状态(更改为 0 或 1)并在我的表上调用 Ajax.reload() 。
问题是 Controller 在每次重新加载时都会收到相同的参数值。看来这部分没有随着重新加载而运行:
"ajax": {
"url": "@Url.Action("GetProjects", "mytool",new { cyfy = "_Switch" })".replace("_Switch",Switch),
"type": "get",
"datatype": "json"
},
我在想是否有办法在数据表 ajax.realod 上传递不同的参数值?
下面是代码的较大部分:
$("#toggle").change(function () {
if ($('#toggle').is(':checked') == true) {
Switch = 1
}
else {
Switch = 0
}
/////////////////
var oTable = $('#myDatatable').DataTable({
"bPaginate": false,
dom: 'Bifrtp',
"ajax": {
"url": "@Url.Action("GetProjects", "mytool",new { cyfy = "_Switch" })".replace("_Switch",Switch),
"type": "get",
"datatype": "json"
},
最佳答案
已解决。 问题是 Ajax 在重新加载时向请求添加时间戳。
为了解决这个问题,我在创建表时添加了 cache : true,
选项。
然后我使用 ajax.url 重新加载表格
var testURL = CreateUrl("mytool/GetProjects?cyfy=") + Switch;
$('#myDatatable').DataTable().ajax.url(testURL).load();
关于javascript - 更改数据表中使用的参数 ajax url.Action on Ajax.reload,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46663862/