2013-05-02 97 views
0

我在我的控制器中有這個;爲什麼這會拋出一個內部服務器錯誤

public JsonResult Json_GetStoreList() 
    { 
     StoresData stores = new StoresData(); 
     return Json(stores.All()); 
    } 

然後在我的部分觀點中,我有這個;

$(function() { 

    $.ajax({ 
     url: '/Maintenance/Json_GetStoreList', 
     dataType: 'json', 
     success: function (data) { 
      alert(data); 
     }, 
     error: function (xhr, ajaxOptions, thrownError) { 
      alert(xhr.status); 
      alert(thrownError); 
     } 
    }); 
}); 

控制器正在返回名爲Store的對象的IEnumerable列表,它看起來像這樣;

public class Store 
{ 
    public Guid id { get; set; } 
    public int number { get; set; } 
    public string name { get; set; } 
} 

的JavaScript拋出錯誤

500 - 內部服務器錯誤

+0

放在服務器方法一個破發點,看看什麼東西扔。使用Fiddler2並觀察請求流量並在500錯誤響應中使用web視圖,您將看到.Net異常頁面。 – asawyer 2013-05-02 04:06:43

+0

嘗試添加此contentType:'application/json – TGH 2013-05-02 04:06:47

+0

可能是一個異常,調試並捕獲它,以便我們現在可以做到這一點。 – 2013-05-02 04:07:00

回答

0

嘗試添加WebMethod屬性

[WebMethod]  
public JsonResult Json_GetStoreList() 
0

試試這個

控制器

[HttpPost] 
    public ActionResult Json_GetStoreList(MyViewModel myViewModel) 
    {    
    StoresData stores = new StoresData(); 
    return Json(stores , JsonRequestBehavior.DenyGet); 
    } 

的Javascript

$.ajax({ 
     url: '/Maintenance/Json_GetStoreList', 
     type: 'POST', 
     dataType: 'json', 
     contentType: 'application/json; charset=utf-8', 
     async: true, 
     processData: false, 
     error: function (xhr) { 
      alert('Error: ' + xhr.statusText); 
     }, 
     success: function (result) { 
      CheckIfInvoiceFound(result); 
     }, 

     }); 
+0

將類型更改爲GET並將控制器更改爲HttpGet和請求行爲AllowGet並且你有答案 – griegs 2013-05-02 04:21:57

相關問題