【问题标题】:ASP.Net MVC3 Razor Jqgrid not rendering the View PageASP.Net MVC3 Razor Jqgrid 不呈现视图页面
【发布时间】:2014-01-13 12:09:27
【问题描述】:

在我的项目中,我必须实现 Datagrid View。经过多次研究,我发现 Jqgrid 在 asp.net mvc3 razor 的自定义 Grid 视图中更加灵活。 因此,通过阅读教程 [Using jQuery Grid With ASP.NET MVC][1] 我创建了一个控制器和一个视图。但现在它没有呈现视图页面。当我单击索引页面中的链接时,它只显示错误 404 .页面未找到。

我的控制器代码

      [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/

查看页面

@{
    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>

【问题讨论】:

  • 也许您需要 HttpGet 而不是 HttpPost 属性来指定。或者另一个带有 HttpGet 的 ActionResult 来呈现这个网格......
  • @xurca 当我使用 Httpget 时,同样的结果也在发生......没有变化。我都试过了。
  • @xurca..你好我已经编辑了代码。现在页面呈现没有网格。只是一个空白页
  • 那么检查你的浏览器是否抛出一些 js 异常并检查你的 js 代码我认为它不正确
  • 在 jqGrid 块中你有额外的括号] 这个。检查它们并删除

标签: asp.net-mvc-3 jqgrid


【解决方案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'}]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2018-02-24
    • 1970-01-01
    • 2019-05-02
    • 2011-03-21
    相关资源
    最近更新 更多