This is the my view code edit button working successfully. i want to delete particular selected record. when your click delete icon model popup will open then it will ask yes or no. if user click yes i need to call action method. how to call that method? when i try to run parameter null its coming to action method.
<table id="mytable" class="table table-bordred table-striped">
<thead>
<tr>
<th>User ID</th>
<th>User Name</th>
<th>Email</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
@foreach (var gt in Model.UserList)
{
<tr>
<td>@gt.UserId</td>
<td>@gt.UserName</td>
<td>@gt.Email</td>
@using (Ajax.BeginForm("getUserDetailById", new AjaxOptions() { UpdateTargetId = "Edit-User", AllowCache = true, InsertionMode = InsertionMode.ReplaceWith,LoadingElementId="resultLoadingDiv" }))
{
@Html.Hidden("userId", @gt.UserId)
<td><p data-placement="top" data-toggle="tooltip" title="Edit/View"><button class="btn btn-primary btn-xs" data-title="Edit/View" data-toggle="modal" data-target="#edit"><span class="glyphicon glyphicon-pencil"></span></button></p></td>
}
<td><button class="btn btn-danger btn-xs delete" data-userid="@gt.UserId" data-title="Delete"><span class="glyphicon glyphicon-trash"></span></button></td>
</tr>
}
</tbody>
</table>
Script:
debugger;
$('#mytable').on('click', '.delete', function () {
var userId = $(this).data('UserId');
if (bootbox.confirm('Do you want to delete this item?', function (result)
{
if (result == true) {
$.ajax({
type: "POST",
url: "Admin/deleteUser/" + userId,
success: function (result) {
},
complete: function () {
},
error: function (xhr, status, errorThrown) {
}
});
}
else {
return;
}
}));
})
My Controller:
[HttpPost]
public JsonResult deleteUser(string userId)
{
_objuser = new UserService();
var status = true;
var gt = _objuser.deleteUserDetail(userId);
return new JsonResult { Data = status, JsonRequestBehavior =
JsonRequestBehavior.AllowGet };
}
may be the problem with controller action only.