MVC3-RAZOR尝鲜2细说实用的WebGrid
2010-12-05 17:04 撞破南墙 阅读(8241) 评论(17) 编辑 收藏 举报1WebGrid的方法签名
public WebGrid(
IEnumerable<dynamic> source, 设置数据源
IEnumerable<string> columnNames = null, 要显示的列名
string defaultSort = null, 默认排序的字段
int rowsPerPage = 10, 每页的行数
bool canPage = true, 是否允许分页
bool canSort = true, 是否允许排序
string ajaxUpdateContainerId = null,
string ajaxUpdateCallback = null,
string fieldNamePrefix = null,字段名的前缀
string pageFieldName = null,
string selectionFieldName = null,
string sortFieldName = null,
string sortDirectionFieldName = null);
代码
for (int i = 0; i < 210; i++) {
list.Add(new CMS5_Razor.Models.Test() { Name = "name" + i, Order = i, Content = "content" + i });
}
var grid = new WebGrid(source: list, rowsPerPage: 5, canPage: true
, selectionFieldName: "Name"
, fieldNamePrefix: "字段名的前缀"
);
2WebGrid.GetHtml函数签名
public IHtmlString GetHtml(
string tableStyle = null,表格样式
string headerStyle = null,头部
string footerStyle = null, 底部
string rowStyle = null, 每一行的样式
string alternatingRowStyle = null, 交替行
string selectedRowStyle = null, 被选中
string caption = null,标题
bool displayHeader = true, 是否显示头部
bool fillEmptyRows = false, 是否填充空行
string emptyRowCellValue = null, 空行里每个字段显示的值
IEnumerable<WebGridColumn> columns = null, 在这里设置各列
IEnumerable<string> exclusions = null, 不显示的字段
WebGridPagerModes mode =枚举值,一般情况选择WebGridPagerModes.All
string firstText = null, 对应第一页链接显示的文字
string previousText = null, 对应上一页链接显示的文字
string nextText = null, 对应下一页链接显示的文字
string lastText = null, 对应最后一页链接显示的文字
int numericLinksCount = 5,数字选择项的数目
object htmlAttributes = null ~beta版本源码中没查到,暂时不知道如何使用,
);
3Column的方法签名
public WebGridColumn Column(string columnName = null,
string header = null,列头的名字
Func<dynamic, object> format = null, 自定义的输出,非常实用
string style = null, 样式
bool canSort = true);是否允许排序
columns: grid.Columns(
grid.Column("Name", "名字", style: "mynameStyle"),
grid.Column("Content", "Content", style: "mynameStyle"),
grid.Column("Order", "顺序", format: @<b><i>@item.Order</i></b>, canSort: false)
), tableStyle: "grid", headerStyle: "headerStyle1", selectedRowStyle: "selectedRowStyle",
caption: "我是标题", displayHeader: !IsPost,
fillEmptyRows: !IsPost, emptyRowCellValue: "这行没东西",
mode: WebGridPagerModes.All, firstText: "第一页",
previousText: "上一页", nextText: "下一页", lastText: "最后一页",
numericLinksCount: 15
)
效果
我的感受:
1 功能非常多。常用的基本上都包括了。 包括分页和排序。
2 似乎之前MVC2的时候是没有辅助生产表格的。而且之前开源社区提供的contribute库也没有这个好用。
3 RAZOR为我们做了太多了,太方便了!新手慎用!
4 还有一些特性如 ajaxUpdateContainerId,htmlAttributes 没有使用,也不好说。
作者:撞破南墙
出处:http://www.cnblogs.com/facingwaller/
关于作者:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· AI Agent爆火后,MCP协议为什么如此重要!
· Draw.io:你可能不知道的「白嫖级」图表绘制神器
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· Windows核心编程 进程与线程