无法获取jquery.jqgrid 4.4.1在ASP.NET MVC工作 [英] Unable to get jquery.jqgrid 4.4.1 working in ASP.NET MVC

查看:125
本文介绍了无法获取jquery.jqgrid 4.4.1在ASP.NET MVC工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力让jquery.jqgrid 4.4.1在我的ASP.NET MVC 4溶液工作。我用的NuGet得到jquery.jqgrid 4.4.1安装到我的项目。我试图插入一个非常简单的网格到我的网页,只是为了确保我包括都设置正确。以下是我在我的视图文件。

  @ {
ViewBag.Title =指数;
}
<链接HREF =〜/内容/的site.css的rel =stylesheet属性/>
<链接HREF =〜/内容/ jquery.jqGrid / ui.jqgrid.css的rel =stylesheet属性/>
<链接HREF =〜/内容/主题/基/ jquery.ui.all.css的rel =stylesheet属性/>                <脚本SRC =〜/脚本/ jQuery的-1.7.2.min.js>< / SCRIPT>
    <脚本SRC =〜/脚本/国际化/ grid.locale-en.js>< / SCRIPT>
    <脚本SRC =〜/脚本/ jquery.jqGrid.min.js>< / SCRIPT>
< H2>指数< / H>
<脚本类型=文/ JavaScript的>
    $(文件)。就绪(函数(){
    $(#myGrid)。jqGrid的({
        网址:'@ Url.Action(GetJqGridData)',
        数据类型:JSON,
        的myType:GET,
        colNames:'ID','名称'],
        colModel:
        {名称:'ID',索引:ID},
        {名称:'名',索引:名称}
        ]
        jsonReader:{
            根:数据,
        ID:'ID',
        repeatitems:假的
        },
        寻呼机:$('#myPager'),
        的rowNum:5,
        rowList:[2,5,10],
        宽度:600,
        viewrecords:真实,
        标题:jqGrid的MVC教程
    });
});
< / SCRIPT>    <表ID =myGrid>< /表>
    < D​​IV ID =myPager>< / DIV>

下面是运行解决方案时,我收到了JavaScript错误。


  

未处理的异常在第54行,在现场5列/网格


  
  

0x800a01b6 - JavaScript的运行时错误:对象不支持属性或方法的jqGrid


视图从来没有到达要求的数据控制的地步。

任何帮助将大大AP preciated。

更新
这里是发送到浏览器为附加细节的HTML。
    
    
        
            
            首页 - 我的ASP.NET MVC应用程序
            
            
            

 <脚本的src =/脚本/ Modernizr的-2.5.3.js>< / SCRIPT>    < /头>
    <身体GT;
        <报头GT;
            < D​​IV CLASS =内容包装>
                < D​​IV CLASS =浮动左>
                    < p =类网站标题>< A HREF =/>此处您的标志和LT; / A>< / P>
                < / DIV>
                < D​​IV CLASS =浮右>
                    <节ID =登录>
                            < UL>
        <立GT;< A HREF =/帐号/注册ID =registerLink>注册< / A>< /李>
        <立GT;< A HREF =/帐号/登录ID =LOGINLINK>登录上述< / A>< /李>
    < / UL>                    < /节>
                    <&导航GT;
                        < UL ID =菜单>
                            <立GT;< A HREF =/>家庭和LT; / A>< /李>
                            <立GT;< A HREF =/首页/关于>关于< / A>< /李>
                            <立GT;< A HREF =/格>电网测试与LT; / A>< /李>
                            <立GT;< A HREF =/首页/联系>联系与LT; / A>< /李>
                        < / UL>
                    < / NAV>
                < / DIV>
            < / DIV>
        < /头>
        < D​​IV ID =身体>            <节类=内容包装主要内容清晰修复><链接HREF =/内容/的site.css的rel =stylesheet属性/>
<链接HREF =/内容/ jquery.jqGrid / ui.jqgrid.css的rel =stylesheet属性/>
<链接HREF =/内容/主题/基/ jquery.ui.all.css的rel =stylesheet属性/><脚本的src =/脚本/ jQuery的-1.7.2.min.js类型=文/ JavaScript的>< / SCRIPT>
<脚本的src =/脚本/国际化/ grid.locale-en.js类型=文/ JavaScript的>< / SCRIPT>
<脚本的src =/脚本/ jquery.jqGrid.min.js类型=文/ JavaScript的>< / SCRIPT>
< H2>指数< / H>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
    $(#myGrid)。jqGrid的({
        网址:'/表格/ GetJqGridData',
        数据类型:JSON,
        的myType:GET,
        colNames:'ID','名称'],
        colModel:
        {名称:'ID',索引:ID},
        {名称:'名',索引:名称}
        ]
        jsonReader:{
        根:数据,
        ID:'ID',
        repeatitems:假的
        },
        寻呼机:$('#myPager'),
        的rowNum:5,
        rowList:[2,5,10],
        宽度:600,
        viewrecords:真实,
        标题:jqGrid的MVC教程
    });
});
< / SCRIPT><表ID =myGrid>< /表>
< D​​IV ID =myPager>< / DIV>
            < /节>
        < / DIV>
        <页脚GT&;
            < D​​IV CLASS =内容包装>
                < D​​IV CLASS =浮动左>
                    < P>&安培;复印件; 2012 - 我的ASP.NET MVC应用程序和LT; / P>
                < / DIV>
            < / DIV>
        < /页脚>        <脚本的src =/脚本/ jQuery的-1.7.2.js>< / SCRIPT>
    < /身体GT;
< / HTML>


解决方案

我启动了一个新项目,并通过的NuGet包安装的网格,它看起来对我来说,你是导致与默认的资源打捆这是一个冲突设置与现在默认MVC4项目。你要么需要从视图中删除以下行/共享/ _layout文件:

  @ Scripts.Render(〜/包/ jQuery的)

这将删除捆绑的脚本。

或添加您的jqGrid脚本引用在App_Start文件夹中的捆绑配置,然后从视图中删除脚本标记。

  bundles.Add(新ScriptBundle(〜/包/ jQuery的)。包括(
                            〜/脚本/ jquery- {}版本的.js
                            〜/脚本/国际化/ grid.locale-en.js
                            〜/脚本/ jquery.jqGrid.min.js));<!----删除这些从你的观点-------&GT!;
<脚本SRC =〜/脚本/ jQuery的-1.7.2.min.js>< / SCRIPT>
<脚本SRC =〜/脚本/国际化/ grid.locale-en.js>< / SCRIPT>
<脚本SRC =〜/脚本/ jquery.jqGrid.min.js>< / SCRIPT>

I have been struggling to get jquery.jqgrid 4.4.1 working in my ASP.NET MVC 4 solution. I used NuGet to get jquery.jqgrid 4.4.1 installed into my project. I am attempting to insert a very simple grid into my page, just to make sure that my includes are all setup correctly. Here is what I have in my View file.

@{
ViewBag.Title = "Index";
}
<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<link href="~/Content/themes/base/jquery.ui.all.css" rel="stylesheet" />

                <script src="~/Scripts/jquery-1.7.2.min.js"></script>
    <script src="~/Scripts/i18n/grid.locale-en.js"></script>
    <script src="~/Scripts/jquery.jqGrid.min.js"></script>


<h2>Index</h2>
<script type="text/javascript">
    $(document).ready(function() {
    $("#myGrid").jqGrid({
        url:'@Url.Action("GetJqGridData")',
        datatype:'json',
        myType:'GET',
        colNames:['Id', 'Name'],
        colModel:[
        { name: 'Id', index: 'Id'},
        { name: 'Name', index: 'Name'}
        ],
        jsonReader: {
            root: 'Data',
        id: 'id',
        repeatitems: false
        },
        pager: $('#myPager'),
        rowNum:5,
        rowList: [2, 5, 10],
        width:600,
        viewrecords:true,
        caption: 'Jqgrid MVC Tutorial'
    });
});
</script>

    <table id="myGrid"></table>
    <div id="myPager"></div>

Here is the Javascript error that I am receiving when running the solution.

Unhandled exception at line 54, column 5 in site/Grid

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'jqGrid'

The View never even gets to the point of calling the controller for the data.

Any help would be greatly appreciated.

Updated Here is the HTML that is sent to the browser for additional detail. Index - My ASP.NET MVC Application

        <script src="/Scripts/modernizr-2.5.3.js"></script>

    </head>
    <body>
        <header>
            <div class="content-wrapper">
                <div class="float-left">
                    <p class="site-title"><a href="/">your logo here</a></p>
                </div>
                <div class="float-right">
                    <section id="login">
                            <ul>
        <li><a href="/Account/Register" id="registerLink">Register</a></li>
        <li><a href="/Account/Login" id="loginLink">Log in</a></li>
    </ul>

                    </section>
                    <nav>
                        <ul id="menu">
                            <li><a href="/">Home</a></li>
                            <li><a href="/Home/About">About</a></li>
                            <li><a href="/Grid">Grid Test</a></li>
                            <li><a href="/Home/Contact">Contact</a></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>
        <div id="body">

            <section class="content-wrapper main-content clear-fix">

<link href="/Content/Site.css" rel="stylesheet" />
<link href="/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
<link href="/Content/themes/base/jquery.ui.all.css" rel="stylesheet" />

<script src="/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="/Scripts/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="/Scripts/jquery.jqGrid.min.js" type="text/javascript"></script>


<h2>Index</h2>
<script type="text/javascript">
$(document).ready(function() {
    $("#myGrid").jqGrid({
        url:'/Grid/GetJqGridData',
        datatype:'json',
        myType:'GET',
        colNames:['Id', 'Name'],
        colModel:[
        { name: 'Id', index: 'Id'},
        { name: 'Name', index: 'Name'}
        ],
        jsonReader: {
        root: 'Data',
        id: 'id',
        repeatitems: false
        },
        pager: $('#myPager'),
        rowNum:5,
        rowList: [2, 5, 10],
        width:600,
        viewrecords:true,
        caption: 'Jqgrid MVC Tutorial'
    });
});
</script>

<table id="myGrid"></table>
<div id="myPager"></div>
            </section>
        </div>
        <footer>
            <div class="content-wrapper">
                <div class="float-left">
                    <p>&copy; 2012 - My ASP.NET MVC Application</p>
                </div>
            </div>
        </footer>

        <script src="/Scripts/jquery-1.7.2.js"></script>


    </body>
</html>

解决方案

I fired up a new project and installed the grid via the nuGet package and it looks to me is that you are causing a conflict with the default resource bundler that is setup with MVC4 projects by default now. You will either need to remove the following line from the Views/Shared/_Layout file:

@Scripts.Render("~/bundles/jquery")

Which will remove the bundled scripts.

Or add your jqGrid script references to the bundle config in the App_Start folder, and then remove the script tags from your view.

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                            "~/Scripts/jquery-{version}.js",
                            "~/Scripts/i18n/grid.locale-en.js",
                            "~/Scripts/jquery.jqGrid.min.js"));

<!----Remove These From your view-------!>
<script src="~/Scripts/jquery-1.7.2.min.js"></script>
<script src="~/Scripts/i18n/grid.locale-en.js"></script>
<script src="~/Scripts/jquery.jqGrid.min.js"></script>

这篇关于无法获取jquery.jqgrid 4.4.1在ASP.NET MVC工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆