基于asp.net的EasyUI处理封装
EasyUI很好用,真不错....
将在asp.net下使用easyui开发需要处理的一些方法总结出来;
1.默认参数(Params.cs)
1.1 datagird
默认四个参数: order:排序字段,sort:排序方法(asc,desc),page:页码,rows:每页行数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Utility4Net.Web.Object;
namespace easyUI
{
/// <summary>
///Params 的摘要说明
/// </summary>
public class Params
{
public Params()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static string order
{
get { return RequestAccessor.Request("order"); }
}
public static string sort
{
get { return RequestAccessor.Request("sort"); }
}
public static int page
{
get { return RequestAccessor.RequestInt("page", 1); }
}
public static int rows
{
get { return RequestAccessor.RequestInt("rows", 20); }
}
}
}
2.抽象实体(Module.cs)
2.1 datagrid
/// <summary>
/// 构成datagrid的结构
/// </summary>
public class datagrid
{
public int total { get; set; }
public string rows { get; set; }
public string footer { get; set; }
}
/// 构成datagrid的结构
/// </summary>
public class datagrid
{
public int total { get; set; }
public string rows { get; set; }
public string footer { get; set; }
}
3.Json格式(Json.cs)
3.1 datagrid支持Json格式
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;
using Utility4Net;
using Utility4Net.Web;
using Utility4Net.Web.Object;
namespace easyUI
{
/// <summary>
///Json 的摘要说明
/// </summary>
public class Json
{
public Json()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static string datagrid(DataTable dt, int page, int rows, string footer = "")
{
int t = dt.Rows.Count;
page = (page == 0) ? 1 : page;
rows = (rows == 0) ? 10 : rows;
int start = (page - 1) * rows;
int end = page * rows;
end = (end > dt.Rows.Count) ? t : end;
dt = Base.tableFilter(dt, start, end);
return datagrid(dt, t, footer);
}
public static string datagrid(DataTable dt, string footer = "")
{
return datagrid(dt, dt.Rows.Count, footer);
}
public static string datagrid(DataTable dt, int t, string footer = "")
{
datagrid grid = new datagrid { total = t, rows = JsonHelper.toJson(dt), footer = footer };
return datagrid(grid);
}
public static string datagrid(datagrid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("\"total\":" + grid.total.ToString());
sb.Append(",\"rows\":" + grid.rows);
if (grid.footer.Length > 0)
sb.Append(",\"footer\":" + grid.footer);
sb.Append("}");
return sb.ToString();
}
}
}
Tips:
1.Window 7 + IIS7.5 下部署EasyUI的设置
1.设置iis
1.Mime 类型
名称:.json
类型:application/x-javascript
2.脚本映射
路径:*.json
可执行文件:C:\WINDOWS\system32\inetsrv\asp.dll
名称:.json
类型:application/x-javascript
2.脚本映射
路径:*.json
可执行文件:C:\WINDOWS\system32\inetsrv\asp.dll
2.设置webconfig
configuration节点下增加
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/x-javascript" />
</staticContent>
<handlers>
<add name="easyUI" path="*.json" verb="*" modules="IsapiModule" scriptProcessor="C:\WINDOWS\system32\inetsrv\asp.dll" resourceType="Unspecified" />
</handlers>
</system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/x-javascript" />
</staticContent>
<handlers>
<add name="easyUI" path="*.json" verb="*" modules="IsapiModule" scriptProcessor="C:\WINDOWS\system32\inetsrv\asp.dll" resourceType="Unspecified" />
</handlers>
</system.webServer>