在ASP.NET WebForm中,我们有很多列表控件,像GridView等,那在ASP.NET MVC3中,可有列表控件列表?
答案是有,今天给大伙介绍一下ASP.NET MVC3 RAZOR WebGrid的使用。
下面且看介绍:
ASP.NET MVC3 RAZOR WebGrid的方法签名
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);
代码
WebGrid.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版本源码中没查到,暂时不知道如何使用,
);
public WebGridColumn Column(string columnName = null,
string header = null,列头的名字
Func<dynamic, object> format = null, 自定义的输出,非常实用
string style = null, 样式
bool canSort = true);是否允许排序
总结:
ASP.NET MVC3 RAZOR WebGrid 已经包含了列表基本所有的功能,同时也包括分页和排序。
用上:RAZOR WebGrid,似乎方便了,不过新手不要乱用,方便的东西,性能就有所欠缺。
2011/9/8 3:55:42 | ASP.NET MVC3教程 | |