JsonProperty Attribute On Class properties causing errors

I noticed that when a class has Json Property Attributes attached to it's properties the combobox has it's dropdown populated with the list data but there is an error in the selection? Is there a workaround for this?

@page "/counter"
<SfComboBox TValue="int" TItem="Person" DataSource="@people">
    <ComboBoxFieldSettings Text="Name" Value="Id"></ComboBoxFieldSettings>
</SfComboBox>
@code{
    List<Person> people;
    protected override void OnInitialized()
    {
        base.OnInitialized();
        people = new List<Person>
{
            new Person
            {
                Id =1,
                Age = 35,
                Name = "Paul"
            },
            new Person
            {
                Id =2,
                Age =45,
                Name= "Julie"
            }
        };
    }
    public class Person
    {
        [Newtonsoft.Json.JsonProperty("id")]
        public int Id { get; set; }
        [Newtonsoft.Json.JsonProperty("age")]
        public int Age { get; set; }
        [Newtonsoft.Json.JsonProperty("name")]
        public string Name { get; set; }
    }
}

2 Replies 1 reply marked as answer

PS paul stanley July 13, 2020 08:43 AM UTC

I noticed this on Stackoverflow:https://stackoverflow.com/questions/52774700/lowercase-property-names
var client = new DocumentClient(new Uri(""), "", serializerSettings: new JsonSerializerSettings
    {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
    });
The only reason for the propertyname attribute was to conform to the CosmosDb camelcase json properties. So
it looks like I can do away with the [Jsonproperty()] now.





SN Sevvandhi Nagulan Syncfusion Team July 15, 2020 11:39 AM UTC

Hi Paul, 


Greetings from Syncfusion support. 


When using the JsonProperty for class objects, you'll need to map the name of the fields with the corresponding name. Refer to the code below, 

<SfComboBox TValue="int" TItem="Person" DataSource="@people"> 
<ComboBoxFieldSettings Text="name" Value="id"></ComboBoxFieldSettings> 
</SfComboBox> 


By using the names of the fields as mentioned above, the elements in the list appear empty. We considered this issue as bug at our end and this fix will be included in our upcoming release which is expected to be rolled out on 22th July,2020. We appreciate your patience until then. 

You can now track the issue from the below feedback link, 


Regards, 
Sevvandhi N 


Marked as answer
Loader.
Up arrow icon