GetTeams後端成功地返回一個列表..但我甚至不能console.log數據也不做任何事情。如果我有GetTeams回報:嘗試從後端接收POST數據時發生內部服務器錯誤; ASP.NET MVC與AngularJS
return Json("testing", JsonRequestBehavior.AllowGet);
它工作正常。我無法理解這裏發生了什麼,爲什麼這不起作用。有人能幫我嗎?由於
ASP.NET MVC
[HttpPost]
public JsonResult GetTeams(int leagueId)
{
try
{
using (var sdb = new SoccerDataEntities())
{
var teamList = (from teams in sdb.footballTeams
orderby teams.name ascending
where teams.league_id == leagueId
select teams).ToList();
return Json(teamList, JsonRequestBehavior.AllowGet);
}
}
catch (Exception e)
{
return Json(false, JsonRequestBehavior.DenyGet);
}
}
角控制器
HeadlinesFactory.getTeamsFromLeague(league.LeagueId)
.success(function (data) {
console.log(data);
});
編輯:
類
public class footballTeam
{
public footballTeam();
public string coach { get; set; }
public virtual footballLeague footballLeague { get; set; }
public int id { get; set; }
public int league_id { get; set; }
public string name { get; set; }
public int season_id { get; set; }
public int team_id { get; set; }
public string TeamDetails { get; set; }
}
public class footballLeague
{
public footballLeague();
public virtual ICollection<footballFeedUpdate> footballFeedUpdates { get; set; }
public virtual ICollection<footballPlayer> footballPlayers { get; set; }
public virtual ICollection<footballPromotionRelegation> footballPromotionRelegations { get; set; }
public virtual ICollection<footballTeam> footballTeams { get; set; }
public bool? groups { get; set; }
public int league_id { get; set; }
public string name { get; set; }
}
SQL列
- ID
- TEAM_ID
- league_id
- season_id
- 名
- 教練
- TeamDetails
就像一個測試,你可以刪除使用語句。這類事情幾乎總是與處理可查詢事件有關。儘管如此,你正在用.ToList()解決,如果情況並非如此,你會認爲你至少會得到一個錯誤。 –
作爲一個額外的測試,您是否也可以在您的select中返回一個teams.name集合,以查看它是否是無法序列化的團隊的屬性。 –
@JoshuaBelden好吧現在就讓我試試 – user1189352