使用ASP.net接收Angular2 POST

时间:2017-03-09 16:44:12

标签: asp.net angular

我有这个方法:

public class Tournament
{
    public int TournamentId { get; set; }
    public string Name { get; set; }
    public virtual List<Game> Games { get; set; }
    public virtual List<Standing> Standings { get; set; }
}

public class Game
{
    public int GameId { get; set; }
    public Location Location { get; set; }
    public int LocationId { get; set; }
    public virtual Team Team1 { get; set; }
    public int Team1Id { get; set; }
    public virtual Team Team2 { get; set; }
    public int Team2Id { get; set; }
    public int Team1Score { get; set; }
    public int Team2Score { get; set; }
    public DateTime Time { get; set; }
    public Tournament Tournament { get; set; }
    public int TournamentId { get; set; }
}

public class Team
{
    public int TeamId { get; set; }
    public string Name { get; set; }
    public string Coach { get; set; }
}

在我的ASP.net控制器中,我有:

this.formatted

但都收到空?我需要做什么?

2 个答案:

答案 0 :(得分:0)

在.NET端创建一个与您从JavaScript发送的对象相匹配的对象。

public class TheRequest
{
    public string JsonSearchCards { get; set; }
}

然后将该参数设为API方法。

答案 1 :(得分:0)

这是一个ASP.NET问题,而不是Angular 2问题。

只需将变量添加到控制器方法的签名中:

public IHttpActionResult FindParts(string JsonSearchCards)
{
}