Ren*_*ado 5 c# asp.net asp.net-mvc asp.net-core-mvc visual-studio-2015
我在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);
});
Run Code Online (Sandbox Code Playgroud)
在我的控制器中我有:
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);
}
Run Code Online (Sandbox Code Playgroud)
之前我在6 beta 4中使用Asp.Net MVC并且这个代码工作正常.
知道什么可能是错的吗?
我的路线:
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?}");
});
Run Code Online (Sandbox Code Playgroud)
我怀疑下面的代码,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()
};
Run Code Online (Sandbox Code Playgroud)
它不会转换为 JSON ...对吗?
| 归档时间: |
|
| 查看次数: |
1316 次 |
| 最近记录: |