2013-05-02 111 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

相关问题