Reputation: 426
In my project i have to implement Datagrid View.After several research i found that Jqgrid is more flexible in custom Gird view in asp.net mvc3 razor. So by reading the tutorial [Using jQuery Grid With ASP.NET MVC][1] i have created a controller and a view .But now its not rendering the view page.When i click the link from index page its just showing that error 404.Page not found.
My Controller Code
[HttpGet]
public ActionResult ViewEmployeeData()
{
return View();
}
[HttpPost]
public ActionResult ViewEmployeeData(string Eord, string Empid, int page, int rows)
{
ElixirERPContext empdata = new ElixirERPContext();
var query = from emp in empdata.EmpData
select emp;
var count = query.Count();
var resultquery = new
{
tottal = 1,
page = page,
records = count,
rows = query.Select(x => new { x.EmpId, x.FirstName, x.MiddleName, x.LastName, x.Address, x.DateOfJoining, x.Department, x.Position }).ToList()
.Select(x => new { id = x.EmpId,Date=x.DateOfJoining, cell = new string[] { x.EmpId.ToString(), x.FirstName, x.MiddleName, x.LastName, x.Address, x.DateOfJoining.ToString(), x.Department, x.Position } }).ToArray(),
};
return Json(resultquery, JsonRequestBehavior.AllowGet);
//return View();
}
[1]: htt
p://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx/
View Page
@{
ViewBag.Title = "ViewEmployeeData";
Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
@* Script For Jqgrid*@
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list").jqGrid({
url: '/Home/ViewEmployeeData/',
datatype: 'json',
mtype: 'GET',
colNames: ['EmpId', 'FirstName', 'MiddleName', 'LastName', 'Address', 'DateOfJoining', 'Department', 'Position'],
colModel: [
{ name: 'EmpId', index: 'EmpId', width: 40, align: 'left' },
{ name: 'FirstName', index: 'FirstName', width: 40, align: 'left' },
{ name: 'LastName', index: 'LastName', width: 200, align: 'left'}],
{ name: 'LastName', index: 'LastName', width: 200, align: 'left'}],
{ name: 'Address', index: 'Address', width: 200, align: 'left'}],
{ name: 'DateOfJoining', index: 'DateOfJoining', width: 200, align: 'left'}],
{ name: 'Department', index: 'Department', width: 200, align: 'left'}],
{ name: 'Position', index: 'Position', width: 200, align: 'left'}],
pager: jQuery('#pager'),
width: 660,
height: 'auto',
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: 'EmpId',
sortorder: "desc",
viewrecords: true,
caption: 'Employee Information'
});
});
</script>
<h2>ViewEmployeeData</h2>
<table id="list" ></table>
<div id="pager"></div>
Index Page
<li><a href="#"><i class="icon-table-2"></i>Employee Management</a>
<ul>
<li><a href="@Url.Action("EmployeeRegistration", "Home")"><i class="icon-double-angle-right"></i>Employee registration</a></li>
<li><a href="@Url.Action("ViewEmployeeData", "Home")""><i class="icon-double-angle-right"></i>View/Edit Employee Details</a></li>
</ul>
Upvotes: 0
Views: 392
Reputation: 2426
In jqGrid block you have extra bracets. check them and delete
colModel: [
{ name: 'EmpId', index: 'EmpId', width: 40, align: 'left' },
{ name: 'FirstName', index: 'FirstName', width: 40, align: 'left' },
{ name: 'LastName', index: 'LastName', width: 200, align: 'left'} ],
{ name: 'LastName', index: 'LastName', width: 200, align: 'left'} ],
{ name: 'Address', index: 'Address', width: 200, align: 'left'} ],
{ name: 'DateOfJoining', index: 'DateOfJoining', width: 200, align: 'left'} ],
{ name: 'Department', index: 'Department', width: 200, align: 'left'} ],
{ name: 'Position', index: 'Position', width: 200, align: 'left'}]
Upvotes: 1