5

現在、MVC 3 webgrid に取り組んでいます。ボタンが必要な列の 1 つで、次のコードをビューに配置するときにこれを達成しました。

@grid.GetHtml(columns:
            grid.Columns(
            grid.Column("ID", "id", canSort: true),
            grid.Column("Surname", "surname", canSort: true),
            grid.Column("Forenames", "forename", canSort: true),
            grid.Column(format: @<input type="button" value="View"/>)),
            headerStyle: "header",
            alternatingRowStyle: "alt",
            htmlAttributes: new { id = "DataTable" }
            )

ただし、ページングの目的でグリッド サーバー側を作成したいのですが、以下のコードをアクションに入れると、ボタン列に対してエラーが発生します。

var htmlString = grid.GetHtml(tableStyle: "webGrid",
                                          headerStyle: "header",
                                          alternatingRowStyle: "alt",
                                          htmlAttributes: new { id = "DataTable" },
                                          columns: grid.Columns(
                                                grid.Column("ID", "id", canSort: true),
                                                grid.Column("Surname", "surname", canSort: true),
                                                grid.Column("Forenames", "forename", canSort: true),      
                                                grid.Column(format: @<input type='button' value='View'/>)                                                                          
                                           ));

最初のエラーは、「逐語指定子の後にキーワード、識別子、または文字列が必要です: @」です。

ボタン列で間違った形式を使用していますか?

4

2 に答える 2

3

コード ビハインドで Razor 構文を使用しようとしているようです。ラムダ式を使用して、このようなことを試してください...

gridColumn.Format = (item) =>
{
    return new HtmlString("<input type='button' value='View'/>");
}
于 2011-01-25T13:59:26.853 に答える
3

<text>このようにカミソリのタグを試すことができます。

grid.Column(format: @<text><input type='button' value='View'/></text>)   
于 2013-02-21T17:21:46.740 に答える