jquery - ASP MVC 3 HTTP Post 通过 JQuery 不断返回 500。Url 和 Controller 匹配

标签 jquery asp.net-mvc-3 http-post

我有一个操作链接,我想将其发送到我的 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/

相关文章:

jquery - 在通过其他事件生成的元素上绑定(bind) Jquery 事件

javascript - 如何将此 JSON 响应放入下拉列表中

asp.net-mvc-3 - .NET MVC Server_GetLastError 总是返回缺少 View 错误

http - 如何在 POST 请求中模拟 HTML 表单提交?

PHP 在事先不知道值的情况下获取 $_POST 值

javascript - 嵌套 Masonry 对象

jquery - 将绝对 div 动画化为固定 div

c# - MVC - 如何在 Html.ActionLink 中动态设置@class

jquery - Razor 和 jQuery,附加表格

jquery - 如何使用 JQuery 发布 JSON 数据?