Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3 Webgrid Column

I'm working on a MVC 3 webgrid at the moment, in one of the columns I wish to have a button, I've achieved this when putting the following code in the view.

@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" }
            )

However I wish to create the grid server side for the purpose of paging, but when I put the code below in the action I get a error for for the button column.

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'/>)                                                                          
                                           ));

The first error is "Keyword, identifier, or string expected after verbatim specifier: @".

Am I using the incorrect format on the button column?

like image 776
user415394 Avatar asked Jan 23 '11 18:01

user415394


2 Answers

It looks like you're attempting to use Razor syntax in your code-behind. Try something like this, using a lambda expression...

gridColumn.Format = (item) =>
{
    return new HtmlString("<input type='button' value='View'/>");
}
like image 77
Stuart Davies Avatar answered Nov 05 '22 09:11

Stuart Davies


you can try <text> tag for razor like this;

grid.Column(format: @<text><input type='button' value='View'/></text>)   
like image 34
Idrees Khan Avatar answered Nov 05 '22 09:11

Idrees Khan