在我的项目中,我必须实现Datagrid View。经过多次研究,我发现Jqgrid在asp.net mvc3 razor中的自定义Gird视图中更灵活。 所以通过阅读教程[使用jQuery Grid with ASP.NET MVC] [1]我已经创建了一个控制器和一个视图。但现在它没有渲染视图页面。当我点击索引页面的链接时它只显示错误404 .Page not not found。
我的控制器代码
[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
号码://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx/
查看页面
@{
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>
索引页
<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>
答案 0 :(得分:1)
在jqGrid块中你有额外的支撑。检查并删除
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'}]