我不确定为什么我对Scheduletype类型的枚举不绑定到下面的JSON中的属性类型。其他属性绑定了发现,我还没有在其他地方的枚举约束的问题上存在问题吗?它总是默认第一个。
JSON
{"Id":0,"BulkInsertId":null,"DivisionId":10406,"DivisionName":"17","DivisionOrder":1,"Type":1,"Name":"A1 vs. A2" }
class
public class ScheduleMatchupModel : IScheduleMatchupModel
{
public ScheduleType Type { get; set; }
public int Id { get; set; }
public int DivisionId { get; set; }
public int? DivisionOrder { get; set; }
public string DivisionName { get; set; }
ischedulematchupmodel.cs
public interface IScheduleMatchupModel
{
int Id { get; set; }
ScheduleType Type { get; set; }
scheduletype enum
[DataContract(Namespace = "")]
public enum ScheduleType
{
[EnumMember(Value = "0")]
All = 0,
[EnumMember(Value = "1"), Display(Name = "Pool Play")]
Pool,
[EnumMember(Value = "2"), Display(Name = "Bracket Play")]
Bracket
}
通过enummember属性,您将某些值设置为枚举:
[EnumMember(Value = "0")]
All = 0,
[EnumMember(Value = "1"), Display(Name = "Pool Play")]
Pool,
[EnumMember(Value = "2"), Display(Name = "Bracket Play")]
Bracket
唯一的问题是enummember属性的值属性是字符串:
public string Value { get; set; }
您将整数分配给JSON中的枚举:
{...,"Type":1,... }
因此,您应该尝试将其更改为JSON中的字符串:
{..."Type":"1",... }