In my ASP.NET MVC 4 view, the following is not calling controller action. Click event does get trigger because I can see the alert message. But when I put a breakpoint on the controller action in debug mode, the app does't get to that point and nothing happens when I click 'Ok' on the alert message. I am using LINQ to SQL. Similar calls to save and insert controller actions work fine:
$('#DeletePOC').click(function () {
if (confirm("This action will delete this POC record permanently. Click OK if you want to delete this record; otherwise, click 'Cancel'")) {
disableButton(['#CancelPOC', '#POC']);
$.ajax({
url: '@Url.Action("POCDelete")', type: "POST", dataType: "json",
data: {
SitePOCID: $('#POCId').val()
},
success: function (data) {
$('#POCStatus').html('<div class="success">POC Removed Successfully.</div>');
},
error: function () {
$('#POCStatus').html('<div class="field-validation-error">Some Error Occured in Removing POC.</div>');
}
});
}
});
Controller: I've tested that during debug, app doesn't get to this action method:
[HttpPost]
public ActionResult POCDelete(int id)
{
db.POC_dsp(id);
return Json("");
}
You should give the data same as the function parameters. In your case, your data name should be id(not SitePocId)
$('#DeletePOC').click(function () {
if (confirm("This action will delete this POC record permanently. Click OK if you want to delete this record; otherwise, click 'Cancel'")) {
disableButton(['#CancelPOC', '#POC']);
$.ajax({
url: '@Url.Action("POCDelete")', type: "POST", dataType: "json",
data: {
id: $('#POCId').val()
},
success: function (data) {
$('#POCStatus').html('<div class="success">POC Removed Successfully.</div>');
},
error: function () {
$('#POCStatus').html('<div class="field-validation-error">Some Error Occured in Removing POC.</div>');
}
});
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With