DataTable转换为JsonResult

1、从数据库获取DataTable类型:

DataTable dt = DBConn.GetPageList(pageIndex, pageSize, "select * from erp_process" + pageSort, ref rowCount);

2、DataTable转换为var类型:

var query = from p in dt.AsEnumerable()
                            select new
                            {
                                ID = int.Parse(p["ID"].ToString()),
                                ProcessCode = p["ProcessCode"].ToString(),
                                ProcessName = p["ProcessName"].ToString(),
                                ProcessType = p["ProcessType"].ToString(),
                                ProcessMan = p["ProcessMan"].ToString(),
                                ProcessTypeName = TypeMapping(p["ProcessType"].ToString()),
                                ProcessManName = ManMapping(p["ProcessMan"].ToString())
                            };

3、返回JsonResult类型:

Json(new { rows = query, total = rowCount }, JsonRequestBehavior.AllowGet);

DataTable转换为JsonResult

上一篇:.Net程序员学习Linux最简单的方法 -- 摘抄


下一篇:wkhtmtopdf--高分辨率转HTML成PDF(三)