I am currently working on generating data to be utilized in a chart.js plot by utilizing C# Controller and javascript. The Controller method I have returns a JSONResult to a javascript function.
public JsonResult GetPlansPerDoc(){
//Code to retrieve data from the 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;
}
This is the Javascript code that calls 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 use console.log on the rawData, it displays an Array message in the web console containing the four items in the json result. However, when attempting to access one of the fields of the json result, I encounter an "unknown" error in the web console. How can I properly utilize the json data?