Joris Mathijssen Joris Mathijssen - 8 months ago 54
ASP.NET (C#) Question

Cannot read property 'match' of undefined asp MVC Morris Chart

Good day!

I'm currently working on a dashboard with a morrischart in it. The dashboard is made with ASP MVC.

With javascript i call a function in my controller that returns me my data.

$.get('@Url.Action("Diagram")', function (result) {
console.log(result) #Has the the correct information
element: 'morris-area-chart',
data: result,
xkey: 'period',
ykeys: ['ColliAantal'],
labels: ['Colli aantal'],
pointSize: 1.5,
hideHover: 'auto',
resize: true

"Result" contains the json data i need for the chart.'

The code i show here is the controller code. scorebord is already defined and had the good data in it.

List<ChartData> chartData = new List<ChartData>();
foreach (Scorebord item in scorebord.Take(100))
chartData.Add(new ChartData(item.ColliQty, item.Datum));
var json = JsonConvert.SerializeObject(chartData);
return Json(json, JsonRequestBehavior.AllowGet);
catch (Exception ex)
return null;

The weird thing is, if I go into debug and copy the data that is returned in the controller and past it in directly in the javascript as data, the thing suddenly works!

I hope someone can help me with this, probably simple, problem. Thanks!

Answer Source

Have you already tried to return your json var (only string) instead of an object of type Json?