5

我有一个这样的网格:

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>
4

2 回答 2

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>
于 2013-01-15T02:45:12.670 回答
0

我认为使用模型中的注释要干净得多。

[GridColumn(Title="&nbsp;", SanitizeEnabled=false,EncodeEnabled=false)]
    public IHtmlString RateLink
    {
        get{
            return new HtmlString("<a href=\"" + BaseUrl + Id + "\" target=\"_blank\">Open</a>");
        }
    }

如果您只使用注释,您的 html 只需要:

@Html.Grid(Model).AutoGenerateColumns()
于 2015-10-02T18:31:39.237 回答