尝试从后端接收POST数据时出现内部服务器错误;带有AngularJS的ASP.NET MVC

本文关键字:带有 错误 服务器 AngularJS MVC NET ASP 内部 端接 POST 数据 | 更新日期: 2023-09-27 18:19:52

GetTeams后端成功返回列表。。但我甚至无法控制、记录数据,也无法做任何事情。如果我有GetTeams返回:

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
  • 联盟_id
  • 季节id
  • 名称
  • 教练
  • 团队详细信息

尝试从后端接收POST数据时出现内部服务器错误;带有AngularJS的ASP.NET MVC

使用投影只返回所需的数据,并确保不会从查询中返回任何Linq类型。

        var teamList = (from teams in sdb.footballTeams
            orderby teams.name ascending
            where teams.league_id == leagueId
            select new
            {
             id = teams.id,
             team_id = teams.team_id,
             league_id = teams.league_id,
             season_id = teams.season_id,
             name = teams.name,
             coach = teams.coach,
             TeamDetails = teams.TeamDetails
            }).ToList();
        return Json(teamList, JsonRequestBehavior.AllowGet);