【发布时间】:2014-05-06 20:31:17
【问题描述】:
我正在尝试调用此方法:
// POST: /Manufacturer/Delete/5
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Manufacturer manufacturer = unitOfWork.manufacturerRepository.GetByID(id);
unitOfWork.manufacturerRepository.Delete(manufacturer);
unitOfWork.Save();
return Json(new { ok = true, newurl = Url.Action("Index", "Manufacturer") });
}
使用这个 ajax:
$.ajax({
url: "/Manufacturer/Delete/" + $('#Id').val(),
type: "POST",
contentType: "application/json; charset=utf-8",
headers: {
'RequestVerificationToken': '@TokenHeaderValue()'
},
data: { id: $('#Id').val() },
error: function (data) {
alert("error" + data);
},
success: function (data) {
if (data.ok)
{
$("#Modal").modal('hide');
}
else {
$('.modal-body').html(data);
}
}
})
我签入了提琴手,我可以看到 ID 被正确传递。我将断点放在方法的开头,但没有被击中。之前通话崩溃。 我应该怎么做才能找到导致此崩溃的原因?
来自提琴手的数据:
POST http://localhost:1809/Manufacturer/Delete/34 HTTP/1.1
Host: localhost:1809
Connection: keep-alive
Content-Length: 5
Accept: */*
RequestVerificationToken: TQY9NrchHlFT6IBaTv1R4daiwGoRH0yv3gHJwpatGj
Origin: http://localhost:1809
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:1809/Admin/Index
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: __RequestVerificationToken=r5YwV-v
id=34
【问题讨论】:
-
HTTP 请求和响应是什么样的?
-
如果您使用 debug=true 进行调试,请编辑并写入 HTTP 500 详细错误。
-
尝试数据:JSON.stringify({ id: $('#Id').val() }),
标签: jquery ajax asp.net-mvc