c# – 在MVC 6中没有收到JsonResult的响应

我在beta6中使用ASP.NET MVC 6.

在我的Startup.cs中,我有以下代码:

services.AddMvc().Configure<MvcOptions>(o =>
            {
                o.OutputFormatters.RemoveAll(formatter => formatter.GetType() == typeof(JsonOutputFormatter));
                var jsonOutputFormatter = new JsonOutputFormatter
                {
                    SerializerSettings = { ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore }
                };
                o.OutputFormatters.Insert(0, jsonOutputFormatter);
            });

在我的控制器中我有:

public async Task<JsonResult> Get()
{
    var result = new DataTablesResult();
    List<MyClass> myClass = await _Repository.GetListMyClass();

    result.Data = new List<dynamic>(myClass);
    var resultado = new
    {
        data = result.Data.ToArray()
    };

    return Json(resultado);
}

但是当我运行邮差时,我收到以下消息:
enter image description here

之前我在6 beta 4中使用Asp.Net MVC并且这个代码工作正常.

知道什么可能是错的吗?

UPDATE

我的路线:

app.UseMvc(routes =>
            {
                // add the new route here.
                routes.MapRoute(name: "config",
                   template: "{area:exists}/{controller}/{action}",
                   defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(
                   name: "configId",
                   template: "{area:exists}/{controller}/{action}/{id}",
                   defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(name: "platform",
                    template: "{area:exists}/{controller}/{action}",
                    defaults: new { controller = "Home", action = "Index" });

                routes.MapRoute(name: "platformByUser",
                    template: "{area:exists}/{controller}/{action}/{userId}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                // Uncomment the following line to add a route for porting Web API 2 controllers.
                // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
            });
最佳答案
我怀疑下面的代码,DataTable /动态到JSON ???

**var result = new DataTablesResult();**

List<MyClass> myClass = await _Repository.GetListMyClass();

**result.Data = new List<dynamic>(myClass);**
var resultado = new
{
    data = result.Data.ToArray()
};

它不会转换为JSON ……对吗?

转载注明原文:c# – 在MVC 6中没有收到JsonResult的响应 - 代码日志