MVC控制器传DataTable
作者:互联网
MVC中,控制器return Json(DataTable)会出现错误:
序列化类型为“System.Reflection.RuntimeModule”的对象时检测到循环引用。
解决办法:先序列化,再return
1 public static string ToJson(object obj) 2 { 3 string str; 4 if (obj is string || obj is char) 5 { 6 str = obj.ToString(); 7 } 8 else 9 { 10 var setting = new JsonSerializerSettings() 11 { 12 ReferenceLoopHandling = ReferenceLoopHandling.Ignore 13 }; 14 str = JsonConvert.SerializeObject(obj, setting); 15 } 16 17 return str; 18 }
标签:控制器,obj,string,setting,MVC,str,return,序列化,DataTable 来源: https://www.cnblogs.com/desertion/p/16424248.html