Hi
I have below data returned by API. I want to display ID & Name in deopdown list
{"status":true,"data":[{"id":"66","name":"Amazon Shipping"},{"id":"37","name":"Amazon Shipping 1 KG"},{"id":"62","name":"Amazon Shipping 10 KG"},{"id":"52","name":"Amazon Shipping 2 KG"},{"id":"159","name":"Amazon Shipping 20 KG"},{"id":"53","name":"Amazon Shipping 5 KG"},
public class Root
{
public bool status { get; set; }
public List data { get; set; }
}
public class Data
{
public string id { get; set; }
public string name { get; set; }
}
Thanks
Jignesh KumarPosted Jan 9, 2023, 3:53 AM
Hello,
You need to combine your value and text into another field and then you can use that to bind dropdownvalues,
in above class we have created response with value - Text means you can see
66 - Amazone Shipping,
37 - Amazon Shipping 1 KG
you need to use dropDownList to bind your dropdown, you can assing this list to viewBag or you can use this model in your view model to bind dropdown
Pasang TamangPosted Jan 8, 2023, 1:31 PM
Hi,
As suggested by Aravind, you have to deserialize the JSON string into Root object. Please check below code
Regards,
Pasang
Aravind GovindarajPosted Jan 8, 2023, 11:15 AM
Hi,
First, deserialize the JSON into Root. So you will get in status and data(list of objects)
Follow this to assign into DDL