【问题标题】:Uncaught TypeError: $(...).jqGrid is not a function未捕获的类型错误:$(...).jqGrid 不是函数
【发布时间】:2015-12-11 11:14:30
【问题描述】:

我知道这是一个愚蠢的问题,但是当我使用 ado.net 时我无法弄清楚这个问题。我可以通过使用实体框架按预期运行和使用 jqgrid,但是当我使用 ado.net 时出现此错误。请帮助。几乎敲我的头。我正在附上代码。提前致谢。

$(function ()
{
    $("#ListGrid").jqGrid
        ({
        url: "/TodoList/GetTodoLists",
        datatype: 'json',
        mtype: 'Get',
        colNames: ['Firstname', 'Gender', 'Id', 'LastName', 'Salary'],
        colModel: [
            { key: false, name: 'Firstname', index: 'Firstname', editable: true },
            { key: false, name: 'Gender', index: 'Gender', editable: true },
            { key: true, hidden: true, name: 'Id', index: 'Id', editable: true },
            { key: false, name: 'LastName', index: 'LastName', editable: true },
            { key: false, name: 'Salary', index: 'Salary', editable: true }],
        pager: jQuery('#pager'),
        rowNum: 10,
        rowList: [10, 20, 30, 40],
        loadonce: true,
        height: '100%',
        viewrecords: true,
        caption: 'Todo List',
        emptyrecords: 'No records to display',
        jsonReader: {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            repeatitems: false,
            Id: "0"
        },
        autowidth: true,
        multiselect: false
    });
});
@{
    ViewBag.Title = "TodoList";
}

<h2>TodoList</h2>
<div>
    <table id="ListGrid">

    </table>
    <div id="pager"></div>
</div>

<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/jquery-ui-1.10.4.min.js"></script>
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>
<script src="~/Scripts/TodoList.js"></script>
    using MvcApplication32.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication32.Controllers
{
    public class TodoListController : Controller
    {
        //
        // GET: /TodoList/

        public ActionResult Index()
        {
            return View();
        }
        public JsonResult GetTodoLists(string sidx, string sord, int page, int rows)
        {
            string ConnectionString = ConfigurationManager.ConnectionStrings["EmployeeContext"].ConnectionString;
            SqlDataReader rdr = null;
            List<Employee> l = new List<Employee>();
            SqlDataAdapter da;
            DataSet ds = new DataSet();
            using (SqlConnection connection = new SqlConnection("data source=.; database=Srivatsava; integrated security=SSPI"))
            {
                connection.Open();
                da = new SqlDataAdapter("select * from Employee", connection);
                da.Fill(ds);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    l.Add(new Employee() { ID = int.Parse(dr[0].ToString()), FirstName = dr[1].ToString(), LastName = dr[2].ToString(), Salary = int.Parse(dr[3].ToString()), Gender = dr[4].ToString() });
                }
                //Create an instance of SqlCommand class, specifying the T-SQL command that 
                //we want to execute, and the connection object.
                //SqlCommand cmd = new SqlCommand("Select Id,FirstName,LastName,Salary,Gender from tblEm", connection);
                // rdr = cmd.ExecuteReader();
                /*  while (rdr.Read())
                  {
                      // get the results of each column
                      int id = (int)rdr["ID"];
                      string contact = (string)rdr["FirstName"];
                      string company = (string)rdr["LastName"];
                      int city = (int)rdr["Salary"];
                      string gender = (string)rdr["Gender"];
                      // print out the results
                      Console.Write(contact);
                      Console.Write(city);
                      Console.Write(company);
                      Console.WriteLine(gender);
                      Console.WriteLine(id);
                  }*/
                connection.Close();
                int pageIndex = Convert.ToInt32(page) - 1;
                int pageSize = rows;
                var todoListsResults = l.Select(
                      a => new
                      {
                          a.ID,
                          a.FirstName,
                          a.LastName,
                          a.Salary,
                          a.Gender
                      });
                int totalRecords = todoListsResults.Count();
                var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
                if (sord.ToUpper() == "DESC")
                {
                    todoListsResults = todoListsResults.OrderByDescending(s => s.FirstName);
                    todoListsResults = todoListsResults.Skip(pageIndex * pageSize).Take(pageSize);
                }
                else
                {
                    todoListsResults = todoListsResults.OrderBy(s => s.FirstName);
                    todoListsResults = todoListsResults.Skip(pageIndex * pageSize).Take(pageSize);
                }
                var jsonData = new
                {
                    total = totalPages,
                    page,
                    records = totalRecords,
                    rows = todoListsResults
                };
                return Json(jsonData, JsonRequestBehavior.AllowGet);
            }

            // return View(l);
        }


    }
}

Error showing in IE

【问题讨论】:

  • 它生成的内容非常好。
  • 你能试着交换这两行吗? &lt;script src="~/Scripts/i18n/grid.locale-en.js"&gt;&lt;/script&gt;&lt;script src="~/Scripts/jquery.jqGrid.min.js"&gt;&lt;/script&gt;
  • 我做到了。仍然是个问题。
  • 您能否在打开控制台并重新加载页面后发布您的控制台屏幕截图?
  • 我附上了图片。请让我这样够了吗??

标签: jquery asp.net-mvc jqgrid


【解决方案1】:

在这种情况下,_Layout.cshtml 中有两个对 jquery 库的引用,必须删除(*如果您在 cshtml 文件中包含库标记)才能完全运行脚本,否则您将得到相同的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 2019-06-06
    • 2019-05-24
    • 2021-12-15
    • 2019-10-26
    相关资源
    最近更新 更多