Mvc+ef bootstrap-table using a DataTable

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.