I am trying to create data for use in a chart.js plot using C# Controller and javascript. My Controller method returns a JSONResult to a javascript function.
public JsonResult GetPlansPerDoc(){
//Code to grab data from database
foreach (RadOnc ro in radOncs){
pm = new CKPlanTypeDistributionPlotModel()
{
DPName = ro.LastName,
DPValue = ro.Plans.Count()
};
planList.Add(pm);
}
JsonResult data = Json(planList, JsonRequestBehavior.AllowGet);
return data;
}
Here's the Javascript code calling the Controller method.
$.ajax({
type: 'get',
url: "@Url.Action("GetPlansPerDoc", "HomeData")",
dataType: 'json',
success: function (rawData) {
console.log(rawData);
const data = rawData.DPName;
console.log(data);
When I console.log the rawData I get an Array message in the web console with the four items in the json result. However, when I try and use one of the fields of the json result I get an "unknown" error in web console. How do I use the json data?