简体   繁体   English

无法读取未定义的ASP MVC莫里斯图表的属性“匹配”

[英]Cannot read property 'match' of undefined asp MVC Morris Chart

Good day! 美好的一天!

I'm currently working on a dashboard with a morrischart in it. 我目前正在使用带有morrischart的仪表板。 The dashboard is made with ASP MVC. 仪表板由ASP MVC制成。

With javascript i call a function in my controller that returns me my data. 使用javascript,我在控制器中调用一个函数,该函数将我的数据返回给我。

$.get('@Url.Action("Diagram")', function (result) {
            console.log(result) #Has the the correct information
            Morris.Line({
                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.' “结果”包含图表所需的json数据。

The code i show here is the controller code. 我在这里显示的代码是控制器代码。 scorebord is already defined and had the good data in it. scorebord已经定义好并包含良好的数据。

try
{
    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! 奇怪的是,如果我进入调试程序并复制在控制器中返回的数据,然后将其作为数据直接粘贴到javascript中,则该操作会突然生效!

I hope someone can help me with this, probably simple, problem. 我希望有人可以帮助我解决这个可能很简单的问题。 Thanks! 谢谢!

您是否已经尝试过返回json var(仅字符串)而不是Json类型的对象?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM