0
    [HttpPost]
    public ActionResult accountchange(int id, int accountid, bool activate)
    {
        // Operations
        return Json(new { Model = model, Result = true, Message = "Changed Successfully });
    }

    $('#accountchange-button').click(function () {
        alert("");
        $.post("url/accountchange/", {id:1, accountid:1, activate:1},
            function (data) { $('.result').html(data); }, "json");

    });

总是得到:

POST http://localhost/account/accountchange/ 500 (Internal Server Error)
                f.support.ajax.f.ajaxTransport.sendjquery.min.js:4
                f.extend.ajaxjquery.min.js:4
                f.each.f.(anonymous function)jquery.min.js:4
                (anonymous function)demo:105
                f.event.dispatchjquery.min.js:3
                f.event.add.h.handle.i

任何的想法?

4

2 回答 2

1

在您的代码中,我没有看到模型被定义。这是我对为什么您的应用程序返回 500 应用程序错误的最佳猜测。正如前面在评论中提到的,您可以使用检查元素实用程序来确定服务器实际在抱怨什么。

[HttpPost]
public ActionResult accountchange(int id, int accountid, bool activate)
{
    // Model = model is most likely undefined
    return Json(new { Model = model, Result = true, Message = "Changed Successfully });
}
于 2012-05-04T22:31:57.220 回答
0

您是否在 Global.asax 中设置了路由以接受您传递的 3 个参数?

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}/{accountId}/{activate}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional, accountId = UrlParameter.Optional, activate = UrlParameter.Optional } 
        );
于 2012-05-04T22:30:08.670 回答