@model IEnumerable<Customer>
@{
Layout = null;
WebGrid webGrid = new WebGrid(source: Model, canSort: false);
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.Grid
{
border: 1px solid #ccc;
border-collapse: collapse;
}
.Grid th
{
background-color: #F7F7F7;
font-weight: bold;
}
.Grid th, .Grid td
{
padding: 5px;
border: 1px solid #ccc;
}
.Grid, .Grid table td
{
border: 0px solid #ccc;
}
.Grid a, .Grid a:visited
{
color:blue;
}
</style>
</head>
<body>
@webGrid.GetHtml(
htmlAttributes: new { @id = "WebGrid", @class = "Grid" },
columns: webGrid.Columns(
webGrid.Column("CustomerID", "Customer Id"),
webGrid.Column("ContactName", "Customer Name"),
webGrid.Column("City", "City"),
webGrid.Column("Country", "Country"),
webGrid.Column(null, null, format: @<text>@Html.ActionLink("Select", null, null, new { @class = "select" })</text>)
))
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("body").on("click", ".select", function () {
var row = $(this).closest("tr");
var message = "Selected Row:";
message += "\n\nCustomer Id: " + row.find("td").eq(0).html();
message += "\nContact Name: " + row.find("td").eq(1).html();
message += "\nCity: " + row.find("td").eq(2).html();
message += "\nCountry: " + row.find("td").eq(3).html();
alert(message);
return false;
});
</script>
</body>
</html>