它在localhost上正常工作,但在部署后无效。我正在使用jQuery从控制器中删除:这里我使用的类型:删除,但即使得到,POST也没有用
$("#btnDelete").click(function (e) {
e.preventDefault();
//alert("delete button clicked");
bootbox.confirm("Do you really want to delete this User", function(result) {
if (result) {
$.ajax({
url: "User/DoDelete/"+@Model.ID,
type:"Delete",
success: function() {
// bootbox.alert("USer "+ @Model.ID+" Deleted successFully");
window.location.href = '@Url.Action("Index","User")';
},
error:function() {
bootbox.alert("Error");
}
});
}
});
});
我的控制器是
[HttpDelete]
public ActionResult DoDelete(int id)
{
context = new Cost();
UserEmployee user = context.UserEmployees.Where(x => x.ID == id).FirstOrDefault();
if (user == null)
{
return HttpNotFound();
}
try
{
context.UserEmployees.Remove(user);
context.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return RedirectToAction("Index");
}
我无法理解为什么它在localhost上工作但在部署端没有工作。
答案 0 :(得分:0)
使用如下:
url: '@Url.Action("DoDelete","User",new RouteValueDictionary(new { id = Model.ID}))',
或使用如下
url: '@Url.Action("DoDelete", "User", new { id = Model.ID})',
答案 1 :(得分:0)
非常感谢,编写如下解决问题
<import />