C # MVC bindings list<dapperrow> to Bootstrap-table list

Source: Internet
Author: User

1.Dapper return List<dynamic> Object
    /// <summary>        ///get the paged data recommended by the candidate/// </summary>        /// <param name= "page" ></param>        /// <param name= "pageSize" ></param>        /// <param name= "Candidatename" ></param>        /// <param name= "Allrowscount" ></param>        /// <returns></returns>         Publiclist<Dynamic> Getcandidaterecommendpage (intPageintPageSize,stringCandidatename, out LongAllrowscount) {            varsql =@"SELECT c.name,c.birthday,c.cvid from dbo. Candidate C"; varAllrowscountsql =@"SELECT COUNT (0) from dbo. Candidate"; varRET =Base. dbsession.connection.getpage<Dynamic> (page, PageSize, outAllrowscount, SQL,NULL, Allrowscountsql).            ToList (); returnret; }
2.Controller layer using Newtonsoft.json serialization
 public  jsonresult getrecommends (int
     page, int  pageSize, string   Candidatename) { var  allrowscount = 0l  ;  var  list = RpoJobRepository.NewInstance.GetCandidateRecommendPage ( Page, PageSize, Candidatename, out   Allrowscount            );  return  base . Newtonsoftjson (new  {total = allrowscount, rows =
   protected Jsonresult Newtonsoftjson (object  data, jsonrequestbehavior behavior)        {            return New Newtonsoftjsonresult            {                = data,                = behavior,            };        }
 /// <summary>    ///newtonsoft Serialization Mode/// </summary>     Public classNewtonsoftjsonresult:jsonresult {/// <summary>        ///overriding execution View/// </summary>        /// <param name= "context" >Context</param>         Public Override voidExecuteresult (ControllerContext context) {if(Context = =NULL)            {                Throw NewArgumentNullException ("Context"); } httpresponsebase Response=context.            Httpcontext.response; if(string. IsNullOrEmpty ( This. ContentType)) {response. ContentType= This.            ContentType; }            Else{Response. ContentType="Application/json"; }            if( This. ContentEncoding! =NULL) {Response. ContentEncoding= This.            ContentEncoding; }            if( This. Data! =NULL)            {                varjsonstring = Jsonconvert.serializeobject ( This.                Data); Response.            Write (jsonstring); }        }

The 3.View layer is bound like a list of bound objects
columns: [{                true            },             {                 'Name',                  ' name ',                 this. Nameformatter             }]

The field here is the same as the column name in the first step.

Summarize

Base of 1.dapper. The Dbsession.connection.getpage<dynamic> method returns a list of Dapperrow, Dapperrow inherits Dictionary<string, object>

2.controller returns the object with JSON serialization, if JavaScriptSerializer is used, the result is the JSON format of the dictionary, such as:

"Total": 143694, "Rows": [[{"Key": "Name", "Value": "Chao Paolong"},{"key": "Birthday", "value": "\/date (107712000000) \"},
Using Newtonsoft.Json.JsonConvert serialization is an object format, such as:
{"Total": 143694, "Rows": [{"Name": "Dizzying tenon?", "Birthday": "1973-06-01t00:00:00", "Cvid": "jr027902222r90250000000"},{" Name ":" 閮 å ãºã? "," Birthday ":" 1981-11-01t00:00:00 "," Cvid ": null},

3. Using dynamic types eliminates the need to define ViewModel classes, saving a lot of time.

4. Another way to do this is to use a DataTable to achieve the same goal without trying.

C # MVC bindings list<dapperrow> to Bootstrap-table list

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.