I have two types SalesData and CollectionData. These two types are entirely different type. So when I passed the data to front end i created dynamic data type and passed the data to front end depending on the call.
While receiving data back, I created json data which is array of objects.
Now I am in situation how do i assigned incoming arrays to List or List according to the type.
This is what I have done.
public ActionResult DownloadDataInExcel(List<object>data, int type)
{
if (type == (int)MyEnum.Sales)
{
var mycontacts = JsonConvert.DeserializeObject<List<SalesData>>(data.ToString());
foreach (var item in mycontacts)
{
System.Diagnostics.Debug.WriteLine($"{item.Name}-{item.City}-{item.Country}");
}
}else
{
var mycontacts = JsonConvert.DeserializeObject<List<CollectionData>>(data.ToString());
foreach (var item in mycontacts)
{
System.Diagnostics.Debug.WriteLine($"{item.Name}-{item.City}-{item.Country}");
}
}
//to do: Convert data to Excel File
throw new NotImplementedException();
}

SalesDataorCollectionData?