How to use web grid in mvc4

Here is a code snippet to use Webgrid in mvc

var grid = new WebGrid(ViewBag.List);
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>)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: