MVC+EF returns a dataset to an entity, which is certainly a deterministic entity, but what if the returned entity is indeterminate? After thinking, think that the DataTable should be able to meet the needs, but when the cheerful combination of SQL follows the previous way (return Json (new {total = PageCount, rows = list}, JSONREQUESTBEHAVIOR.A Llowget); return JSON when the foreground receives an error "a circular reference was detected when serializing an object of type" System.Reflection.RuntimeModule " the exact reason is not clear. " But the feeling is that serializing the JSON object is a failure, instead consider returning the JSON-formatted string directly, with the following code:
1Jsonserializersettings setting =Newjsonserializersettings ()2 {3Referenceloophandling =Referenceloophandling.ignore4 };5 6 varRET ="{\ "total\":"+ dt. Rows.Count +", \ "rows\":"+ jsonconvert.serializeobject (dt, setting) +"}";7 8 returnJson (ret, jsonrequestbehavior.allowget);
View Code
It is true that the front desk no longer reports the above error, but does not load the data and looks at the Bootstrap-table API with a ResponseHandler property: A handler before loading the server data that can be used to format the data. Then try to convert the obtained data into a JSON object in the method again, the following code:
function // The background data source returns a JSON string for the DataTable, which needs to be processed into a JSON object res = eval (' (' + res + ') ')return res;
The final data is loaded successfully. At the beginning of the article I mentioned that the dynamic column header and bootstrap-table column headers need to be dynamically obtained from the database, the program I do a special processing foreground will dynamically generate columns, the background will be dynamically generated DataTable table header, display effect.
Mvc+ef bootstrap-table using a DataTable