我正在使用 bootstrap-table 库在我的 ASP.net MVC 视图中创建一个表。每当用户双击表格行时,要求是选择表格行数据并将其传输到模型弹出窗口。
我可以在 Javascript 中使用 row[] 数组选择行列值,但我无法通过 Ajax 将其传输到我的控制器。
请在我的代码片段下方找到:-
<html>
<head>
<script>
$(document).ready(function () {
$('#tblID').bootstrapTable({ locale: 'en-US' }).on('click-row.bs.table', function (e, row, $element) {
var param = row[2]; //fetching 3rd column value
$.ajax({
type: "GET",
url: '@Url.Action("_SampleAction", "SampleController")',
data: '{ID: "' + param + '" }',
datatype: "json",
success: function (result) {
$('#myModelContent').html(result);
$("#myModal").modal('show');
},
error: function (req, status, error) {
alert("Error!Occured");
}
});
});
});
</script>
</head>
<body>
<table id="tblID" class="table table-hover" data-search="true" data-show-columns="true" data-mobile-responsive="true" data-striped="true" data-toggle="table" data-sort-name="Salary" data-sort-order="desc" data-pagination="true" data-smart-display="true" data-filter-control="true" data-show-export="true" data-click-to-select="true" data-page-list="[5, 10, 25, 50, 100, ALL]" data-export-options='{"fileName": "ActiveList","ignoreColumn": ["state"]}'>
<thead>
<tr>
@foreach (DataColumn col in Model.Details.Columns)
{
<th class="TableRowHeader" data-sortable="true" data-filter-control="Select">@col.ColumnName</th>
}
</tr>
</thead>
样本控制器:-
public ActionResult _SampleAction(string ID)
{
MyModel objMyModel = new MyModel ();
objMyModel.ID = ID;
try
{
return PartialView("_SampleAction", objMyModel);
}
catch (Exception ex)
{
return RedirectToAction("Index", "Error");
}
}
但是我收到的参数ID为 null,Ajax 调用失败。
谁能指导我如何实现这一目标?
30秒到达战场
相关分类