I'm using bootstrap-table library to create a table in my ASP.net MVC view. Whenever the user double click on the table row, requirement is to pick the table row data and transfer it to a model popup.
I'm able to pick the row column values using row[] array in Javascript but I'm not able to transfer it to my controller through Ajax.
Please find below my code snippet:-
<html lang="en-AU">
<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>
<tbody>
@foreach (DataRow row in Model.MonitorDetails.Rows)
{
<tr>
@foreach (DataColumn col in Model.MonitorDetails.Columns)
{
<td class="TableBody">@row[col.ColumnName]</td>
}
</tr>
}
</tbody>
</table>
<div class="modal fade" tabindex="-1" id="myModal" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content" style="width: auto;">
<div id='myModalContent'></div>
</div>
</div>
</div>
</body>
</html>
SampleController:-
public ActionResult _SampleAction(string ID)
{
MyModel objMyModel = new MyModel ();
objMyModel.ID = ID;
try
{
return PartialView("_SampleAction", objMyModel);
}
catch (Exception ex)
{
return RedirectToAction("Index", "Error");
}
}
But I'm receiving parameter ID as null and Ajax call fails.
Can anyone please guide me on how to achieve this?
Thanks in advance.