public async Task <ActionResult> CodePreviewJson(BaseConfigModel baseConfig) { try { List <TableFieldInfo> list = await _service.GetTableFieldList(baseConfig.TableName); SingleTableTemplate template = new SingleTableTemplate(_context); DataTable dt = DataTableHelper.ListToDataTable(list); // 用DataTable类型,避免依赖 string idcolumn = string.Empty; Dictionary <string, string> dic = new Dictionary <string, string>(); baseConfig.PageIndex.ButtonList = ExtList.removeNull(baseConfig.PageIndex.ButtonList); baseConfig.PageIndex.ColumnList = baseConfig.PageIndex.ColumnList.Where(a => a.field != "").ToList(); baseConfig.PageForm.FieldList.Remove(""); string idType = "string"; //扩展删除字段和创建时间字段 string[] isDeleteMarkFieldNames = new[] { "F_DeleteMark", "IsDelete" }; string[] createTimeFieldNames = new[] { "F_CreatorTime", "AddTime" }; string isDeleteMarkField = "F_DeleteMark"; string createTimeField = "F_CreatorTime"; foreach (DataRow dr in dt.Rows) { if (dr["TableIdentity"].ToString() == "Y") { idcolumn = dr["TableColumn"].ToString(); string datatype = dr["Datatype"].ToString(); datatype = TableMappingHelper.GetPropertyDatatype(datatype); if (datatype == "int?") { idType = "int"; } else if (datatype == "long?") { idType = "long"; } else { idType = "string"; } } string columnName = dr["TableColumn"].ToString(); foreach (var isDeleteMarkFieldName in isDeleteMarkFieldNames) { if (string.Compare(isDeleteMarkFieldName, columnName, true) == 0) { isDeleteMarkField = columnName; } } foreach (var createTimeFieldName in createTimeFieldNames) { if (string.Compare(createTimeFieldName, columnName, true) == 0) { createTimeField = columnName; } } } string codeEntity = template.BuildEntity(baseConfig, dt, idcolumn); string codeService = template.BuildService(baseConfig, dt, idcolumn, idType, isDeleteMarkField, createTimeField); string codeController = template.BuildController(baseConfig, idcolumn, idType); string codeIndex = template.BuildIndex(baseConfig, idcolumn); string codeForm = template.BuildForm(baseConfig); string codeDetails = template.BuildDetails(baseConfig); string codeMenu = template.BuildMenu(baseConfig, idcolumn); var json = new { CodeEntity = HttpUtility.HtmlEncode(codeEntity), CodeService = HttpUtility.HtmlEncode(codeService), CodeController = HttpUtility.HtmlEncode(codeController), CodeIndex = HttpUtility.HtmlEncode(codeIndex), CodeForm = HttpUtility.HtmlEncode(codeForm), CodeDetails = HttpUtility.HtmlEncode(codeDetails), CodeMenu = HttpUtility.HtmlEncode(codeMenu) }; return(Success("操作成功", json)); } catch (System.Exception ex) { return(Error(ex.Message)); } }