1. Package model
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Namespace MODEL. Formatmodel
{
public class Tablemodel<t>
{
Public T rows {get; set;}
public int total{get;set;}
}
}
2. Methods
Public ActionResult getcontentlist ()
{
int currentpage = httpcontext.request.params["offset"] = = null? 1:int. Parse (httpcontext.request.params["limit"]);
Number of rows per page
int showcount = httpcontext.request.params["limit"] = = null? 10:int. Parse (httpcontext.request.params["limit"]);
if (currentpage! = 0)
{//Get pages
CurrentPage = Currentpage/showcount;
}
CurrentPage + = 1;
List<model. content> allmodellist = OperateContext.Current.BLLSession.IContentBLL.Get (c = 1 = = 1). ToList (). OrderByDescending (c = c.postdate). ToList ();
int rows = Allmodellist.count/showcount;
int total = Allmodellist.count;
List<model. content> modellist = Allmodellist.take (Showcount * currentpage). Skip (Showcount * (currentPage-1)). ToList ();
List<model. content> contentlist = new List<model. Content> ();
MODEL. Content content = NULL;
for (int i = 0; i < Modellist.count; i++)
{
Content = Modellist[i]. ToPo ();
if (!string. Isnullorwhitespace (content. Catalog))
{
String cId = content. Catalog;
MODEL. Catalog Catalogmodel = OperateContext.Current.BLLSession.ICataLogBLL.Get (c = c.id = = cId). FirstOrDefault ();
if (Catalogmodel! = null)
{
Content. Catalog = Catalogmodel.name;
}
Else
{
Content. Catalog = "";
}
}
Else
{
Content. Catalog = "";
}
Contentlist.add (content);
}
System.Text.StringBuilder sb = new StringBuilder ();
System.Web.Script.Serialization.JavaScriptSerializer JSS = new System.Web.Script.Serialization.JavaScriptSerializer ();
Jss. Serialize (ContentList, SB);
string contentlistjsonstr = "\" rows\ ": \" "+ SB. ToString () + "\", \ "total\": \ "" + Total + "\" ";
MODEL. Formatmodel.tablemodel<list<model. content>> TableModel = new MODEL. Formatmodel.tablemodel<list<model. Content>> ();
Tablemodel.rows = ContentList;
Tablemodel.total = total;
Return Json (TableModel, jsonrequestbehavior.allowget);
}
3. Front End
<table data-toggle= "table" id= "table" data-toolbar= "#toolbar" data-url= "/admin/site/getcontentlist" Data-show-refresh= "true" data-show-toggle= "true" data-show-columns= "true" Data-search= "true" data-pagination= "true "data-side-pagination=" Server "data-page-list=" [5, ten, +, +, +] "data-sort-name=" name "data-sort-order=" desc " >
<thead>
<tr>
<th data-field= "state" data-checkbox= "true" class= "Col-sm-1" ></th>
<th data-field= "ID" data-visible= "false" >ID</th>
<th data-field= "title" data-sortable= "true" class= "col-sm-3" > title </th>
<th data-field= "Abbreviations" data-sortable= "true" class= "col-sm-3" > Abbreviations </th>
<th data-field= "Catalog" data-sortable= "true" class= "col-sm-1" > Columns </th>
<th data-field= "Ispublish" data-sortable= "true" class= "Col-sm-1" > Publish </th>
<th data-field= "Poster" data-sortable= "true" class= "Col-sm-1" > Publisher </th>
<th data-field= "Postdate" data-sortable= "true" class= "col-sm-1" > Publish Time </th>
<th data-field= "Operation" data-formatter= "Actionformatter" data-events= "actionevents" class= "col-sm-1" > Operations </th>
</tr>
</thead>
</table>
Bootstrap Table Server Paging