IN Model
{
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Location { get; set; }
public string Name { get; set; }
public string Path { get; set; }
public string Size { get; set; }
public List<Sample> images { get; set; }
public int Id{get;set;}
public List<Sample> Listgrid { get; set; }
KavithaEntities1 context = new KavithaEntities1();
public List<Sample> GetList()
{
List<Sample> ListDetails = new List<Sample>();
Sample Smpl = null;
var list = context.sp_GetList_Jqgrid().ToList();
for (int i = 0; i <
list.Count(); i++)
{
Smpl = new Sample();
Smpl.UserName =
list[i].UserName;
Smpl.FirstName =
list[i].FirstName;
Smpl.LastName =
list[i].LastName;
Smpl.Location =
list[i].Location;
Smpl.Id = Convert.ToInt32(list[i].Id);
ListDetails.Add(Smpl);
}
return ListDetails;
}
}
In controller
public ActionResult
WebGrid()
{
Sample
sample = new Sample();
List<Sample>
lst = new List<Sample>();
lst = sample.GetList();
return
View(lst);
}
In view
@model IEnumerable<JQGridExample.Models.Sample>
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
@{
var grid = new WebGrid(Model, canSort: true, canPage: true, rowsPerPage: 2, ajaxUpdateContainerId: "grid");
}
<html>
<head>
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div class="tableGrid">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="yui">
<thead>
<tr>
<td colspan="5" class="filter">
<div style="float: left; height: 28px;">
<input name="filter" id="filterBox" value="" maxlength="30" size="30" type="text" class="membertextbox" onkeyup="CallMe(1000)" />
<input type="button" name="button" id="btndel" value="Delete" class="redbutton" onclick="return DeleteMember()" >
</div>
<div style="float: right">
</div>
</td>
</tr>
</thead>
<tbody>
@MvcHtmlString.Create(grid.GetHtml(
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "selectedrow",
htmlAttributes: new { id = "managemebers" },
columns: grid.Columns(
grid.Column(header: "{CheckBoxHeading}", format: @<text><input name="chck" class="chkmember" onclick="CheckboxCheck()"
TYPE="checkbox" id="chck" value="@item.Id" /></text>), grid.Column(columnName: "User
Name", format: (item) => Html.ActionLink((string)item.UserName, "EditMember", new { Id = item.Id }, new { @style = "color:#000;text-decoration:underline" }), canSort: true), grid.Column("FirstName", "First Name"), grid.Column("LastName", "Last Name"), grid.Column("Location", "Location"))).ToString().Replace("{CheckBoxHeading}", "<input type='checkbox'
id='chkall' onclick='return checkAll(this.checked)'/>"))
</tbody>
</table>
<div colspan="5" style="background: #E9E9E9;color: #000;vertical-align: middle;font-size: 14px;width:100%;text-align:center">Total rows:@Model.Count()</div>
</div>
<!--rightSection
-->
</body>
</html>