你可以做这样的事情吗?
public class MyWebGrid : WebGrid
{
public WebGridMkf(IEnumerable<dynamic> source = null,
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) :
base(source, columnNames, defaultSort, rowsPerPage, canPage, canSort, ajaxUpdateContainerId, ajaxUpdateCallback, fieldNamePrefix, pageFieldName, sortFieldName, sortDirectionFieldName)
{
}
public IHtmlString Table(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,
Func<dynamic, object> footer = null,
object htmlAttributes = null)
{
if (this.TotalRowCount.Equals(0))
{
return new HtmlString("<div>teste</div>");
}
return base.Table(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle, selectedRowStyle, caption, displayHeader, fillEmptyRows, emptyRowCellValue, columns, exclusions, footer, htmlAttributes);
}
}
并致电:
var grid = new MyWebGrid(
ajaxUpdateContainerId: "grid-test",
rowsPerPage: 10,
defaultSort: "id"
);
grid.Bind(
source: Model.ActivityCollection,
rowCount: Model.ActivityCollection.Count
);
@grid.Table(
alternatingRowStyle: "color1",
rowStyle: "color0",
tableStyle: "webgrid table table-striped table-hover table-condensed",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
footer: @<span></span>,
columns: grid.Columns(
grid.Column(columnName: "id",
header: "ID",
style: "column-id",
canSort: true)
)
)