【发布时间】:2013-11-15 21:53:17
【问题描述】:
我正在尝试学习如何使用 Visual Studio 2012 创建自己的 Web API。我目前通过以下模型设置了两个数据库表。
“国家/地区”表既美观又简单。我可以使用 Fiddler 成功发布新条目。但是,当尝试 POST 到 Players 表时,我收到 500 错误。当然,我不知道哪里出错了。
Player.cs
public class Player
{
public Guid PlayerId { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Address { get; set; }
public string Address2 { get; set; }
[Required]
public string Town { get; set; }
[Required]
public string State { get; set; }
[Required]
public string Postcode { get; set; }
[Required]
public int CountryId { get; set; }
[Required]
public string Email { get; set; }
public string Telephone { get; set; }
public string Mobile { get; set; }
public DateTime? DateJoined { get; set; }
// Navigation properties
public Country Country { get; set; }
}
Countries.cs
public class Country
{
public int CountryId { get; set; }
public string Name { get; set; }
}
我在 Fiddler 请求标头中设置了以下内容类型:
内容类型:应用程序/json;字符集=utf-8
我试图 POST 到 Player 表的数据是这样的:
{"PlayerId":"hfjdfk","Username":"TickledPink","Address":"My Address","Address2":"","Town":"Llanerchymedd","State":"Anglesey ", "邮编":"LL71","Email":"myemail@me.net","电话":"1234567","手机":"456789","DateJoined":"","CountryId":" 1"}
【问题讨论】:
标签: c# asp.net json asp.net-web-api