我有这样的网格:
WebGrid grid = new WebGrid(source: Model, rowsPerPage: 5, ajaxUpdateContainerId: "GridContainer");
现在,我想将“MyContent”列显示为原始HTML。我该怎么办?
<div id="GridContainer">
@grid.GetHtml(columns:
grid.Columns(
grid.Column(
columnName: "MyContent",
//Format: What should I put here?
)
)
)
</div>
答案 0 :(得分:5)
使用
<div id="GridContainer">
@grid.GetHtml(columns:
grid.Columns(
grid.Column(
columnName: "MyContent",
format: (item) =>
{
var links = Html.ActionLink("Edit", "Edit", new {id = item.PrimaryKey}) + " | " +
Html.ActionLink("Details","Details", new { id = item.PrimaryKey}) + " | "+
Html.ActionLink("Delete", "Delete", new { id = item.PrimaryKey});
return Html.Raw(links);
}
)
)
)
呈现为
<td>
<a href="/Home/Edit/5">Edit</a> |
<a href="/Home/Details/5">Details</a> |
<a href="/Home/Delete/5">Delete</a>
</td>
答案 1 :(得分:0)
我认为在模型中使用注释要清晰得多。
[GridColumn(Title=" ", SanitizeEnabled=false,EncodeEnabled=false)]
public IHtmlString RateLink
{
get{
return new HtmlString("<a href=\"" + BaseUrl + Id + "\" target=\"_blank\">Open</a>");
}
}
如果您只使用注释,则html只需要:
@Html.Grid(Model).AutoGenerateColumns()