我正在使用MVC3中的帮助程序Html.WebGrid,如何为每个TR标记包含数据?
我在列中有数据,我不想显示列,我需要将这些数据放在表的TR上,然后使用JavaScript。
谢谢。
修改
public class MyModel
{
public DataTable Data { get; set; }
public IList<dynamic> Results()
{
var columnas = this.Columnas();
var result = new List<dynamic>();
foreach (DataRow row in this.Data.Rows)
{
var obj = (IDictionary<string, object>)new ExpandoObject();
foreach (DataColumn column in columns)
{
if (!columna.ColumnName.StartsWith("_"))
{
obj.Add(column.ColumnName, row[column.ColumnName]);
}
}
result.Add(obj);
}
return result;
}
private IList<DataColumn> Columns()
{
var columns = new List<DataColumn>();
foreach (DataColumn column in this.Data.Columns)
{
columns.Add(column);
}
return columns;
}
}
page.schtml
@model MySite.Model.MyModel
@using System.Data
@{
ViewBag.Title = "My page";
Layout = "~/Views/Shared/Layout.cshtml";
}
<h2>Resultados</h2>
@{
if (Model == null) {
<div>
<div>no results</div>
</div>
}
else {
<div>
<div>Rows: <span>@Model.Data.Rows.Count</span></div>
@{
var grid = new WebGrid(source: Model.Results(), rowsPerPage: 10);
@grid.GetHtml(
fillEmptyRows: true,
alternatingRowStyle: "fila-alternativa",
headerStyle: "encabezado-grid",
footerStyle: "pie-grid",
mode: WebGridPagerModes.All,
firstText: "<< Primera",
previousText: "< Anterior",
nextText: "Siguiente >",
lastText: "Última >>"
)
}
@Html.HiddenFor(model => Model.Filtros.TipoConsultaSiguiente)
</div>
}
}
答案 0 :(得分:1)
配置网格时,您可以为此列设置类
@MvcHtmlString.Create(grid.GetHtml(htmlAttributes: new { id = "grid" },
tableStyle: "members_table",
rowStyle: "alt",
mode: WebGridPagerModes.All,
columns: grid.Columns(
grid.Column(columnName: "Id", format: @<text>@item.id</text>, style: "hiddenColumn"), ...
并在hiddenColumn类中为此列设置可见性。