[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
任何想法?
答案 0 :(得分:1)
在您的代码中,我没有看到模型被定义。这是我最好的猜测,为什么你的应用程序返回500应用程序错误。如前面在评论中提到的,您可以使用inspect元素实用程序来确定服务器实际抱怨的内容。
[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 });
}
答案 1 :(得分: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 }
);