0

I am not sure why my enum of the type ScheduleType doesnt bind to the property Type in the json below. The other properties bind find, and I havent had an issue with an enum binding in other places, thoughts? It always defaults the the first one.

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
}

1 Answer 1

2

By means of the EnumMember attribute you set certain values to your enums:

[EnumMember(Value = "0")]
All = 0,
[EnumMember(Value = "1"), Display(Name = "Pool Play")]
Pool,
[EnumMember(Value = "2"), Display(Name = "Bracket Play")]
Bracket

The only problem is that the Value property of EnumMember attribute is a string:

public string Value { get; set; }

And you assign integers to your enums in your JSON:

{...,"Type":1,... }

You should therefore try to change it to string in your JSON:

{..."Type":"1",... }
Sign up to request clarification or add additional context in comments.

2 Comments

Removing EnumMember has same effect
I made the property a string in Javascript and it works. Kind of weird there isnt a way around this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.