2012-05-04 23 views
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"); 

    }); 

總是有:後總是得到HTTP錯誤500:ASP.NET MVC3

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

您應該在Chrome開發人員工具或Firebug中查看完整的XMLHttpRequest響應。來自服務器的響應將比HTTP狀態代碼具有更多信息。 – jaredhoyt

+0

500是內部服務器錯誤 - 您的服務器錯誤日誌說什麼? –

+0

謝謝jaredhoyt,我將用螢火蟲進行調試 – gandil

回答

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 }); 
} 
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 } 
     ); 
+0

他沒有通過那樣的參數... – psousa

+0

我不在這個動作中使用模型MattSavage – gandil