我有一个操作链接,我想将其发送到我的 Controller ,但是我不断收到 HTTP 500。
这是我的 jQuery
<script type="text/javascript"> $(document).ready(function () { $('.thing').click(function (e) { e.preventDefault(); $.ajax({ url: this.href, dataType: "json", type: "POST", success: function (data) { if (data.Success == true) { // do something } else { alert(data.Message); } }, error: function (textStatus, errorThrown) { // request always errors } }); }); }); </script>
和我的操作链接代码
@Html.ActionLink("my link", "DoStuff", "Dude", new { thingId = item.Id }, new { @class = "thing" })
我的 Controller
public class DudeController : Controller { [HttpPost] public ActionResult DoStuff(int thingId) { return Json(new { Success = true, Message = string.Empty }, JsonRequestBehavior.AllowGet); } }
有什么想法吗?
最佳答案
您可以尝试从ajax调用中删除dateType并添加数据吗?对我来说它有效:
$(document).ready(function () {
$('.thing').click(function (e) {
e.preventDefault();
$.ajax({
url: this.href,
type: "POST",
data: this.thingId,
success: function (data) {
if (data.Success == true) {
// do something
alert(data.Message);
}
else {
alert(data.Message);
}
},
error: function (textStatus, errorThrown) {
// request always errors
}
});
});
});
关于jquery - ASP MVC 3 HTTP Post 通过 JQuery 不断返回 500。Url 和 Controller 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5695772/