I am trying to get data from the following class:
public class SalesData
{
public string RepName { get; set; }
public string DateString { get; set; }
public decimal TotalSales { get; set; }
public decimal RepSales { get; set; }
}
public static class SalesDataBuilder
{
public static List<SalesData> GetCollection()
{
return new List<SalesData>
{
new SalesData
{
RepName = "Nancy Davolio",
DateString = "Aug 2010",
TotalSales = 10458,
RepSales = 2015
},
new SalesData
{
RepName = "Nancy Davolio",
DateString = "Sept 2010",
TotalSales = 21598,
RepSales = 6003
}, };
}
Using Json in my controller, I tried the following:
public JsonResult IndexJson()
{
IEnumerable<SalesData> person = (from e in SalesData
select new SalesData
{
RepName = e.RepName,
RepSales = e.RepSales
});
return Json(person);
}
Certainly I am doing something wrong, being very new to json. I would appreciate your suggestions. Thanks in advance.