How to use web grid in mvc4

December 15, 2014

Here is a code snippet to use Webgrid in mvc

<pre>@{
var grid = new WebGrid(ViewBag.List);
@grid.GetHtml(
tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns
(
grid.Column("Name", header: "Name", format: m => m.Name),
grid.Column("City", header: "City", format: m => m.City),
grid.Column("",header: "Edit", format: @<text> @Html.ActionLink("Edit", "EditStudent", new  {id = item.Id }) </text>),
grid.Column("",header: "Delete", format: @<text>@Html.ActionLink("Delete", "DeleteStudent", new  {id = item.Id }, new { onclick = "javascript:return confirm('Are you sure want to delete this?')" } ) </text>)
)
);
}

Advertisements