Search code examples
c#webgrid

Link to a view in webgrid


I have a webgrid displaying a list of view models. I want to go to a view when the user clicks on one row of the webgrid.

Below is the cshtml part of the webgrid:

WebGrid grid = new WebGrid(Model.ClientMatches);
@grid.GetHtml(columns: new[]

                     {
                grid.Column("Name"),
                grid.Column("Surname"),
                grid.Column("Email"),
            })

Any idea how to do this?


Solution

  • You can do something like this

    grid.Column(columnName: "Name", format: (item) => Html.ActionLink("ActionRoute", "Edit Name", new { Name = item.Name })))
    

    Where Edit Name is the title of the link and the href will redirect to "ActionRoute"