在我的ASP.NET MVC 4视图中,以下内容不是调用控制器操作。 Click事件会触发,因为我可以看到警报消息。但是当我在调试模式下对控制器动作设置断点时,应用程序无法达到这一点,当我在警报消息上单击“确定”时没有任何反应。我正在使用LINQ to SQL。类似的保存和插入控制器操作的调用工作正常:
$('#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>');
}
});
}
});
控制器: 我在调试期间测试过,app没有使用此操作方法:
[HttpPost]
public ActionResult POCDelete(int id)
{
db.POC_dsp(id);
return Json("");
}
答案 0 :(得分:8)
您应该提供与函数参数相同的数据。在您的情况下,您的数据名称应为id(而不是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>');
}
});
}
});