运行时错误"对象[对象对象]没有方法' igGrid' "用于igniteUI网格

时间:2016-02-12 04:53:43

标签: asp.net-mvc ignite-ui iggrid

代码snippit显示运行时错误"对象[object Object]没有方法' igGrid' "

"Uncaught TypeError: Object [object Object] has no method 'igGrid' 
(anonymous function) Index:57
c                    jquery-1.9.1.min.js:3
p.fireWith           jquery-1.9.1.min.js:3
b.extend.ready       jquery-1.9.1.min.js:3
H                    jquery-1.9.1.min.js:3"

页面源也显示以下数据,但不构成IgniteUi Grid

<table id="Grid1"></table>
<script type="text/javascript">$(function () {$('#Grid1').igGrid({ dataSource: {"Records":[{"Id":1,"Title":"roman","Authers":"Romania","publishYear":"1996","BasePrice":18},{"Id":2,"Title":"Half Gf","Authers":"Chetan Bhagat","publishYear":"2005","BasePrice":21},{"Id":3,"Title":"Harry Potter","Authers":"JK Rowling","publishYear":"1998","BasePrice":100},{"Id":4,"Title":"Discover India","Authers":"Nehru","publishYear":"1942","BasePrice":15}],"TotalRecordsCount":0,"Metadata":{"timezoneOffset":19800000}},dataSourceType: 'json',autoGenerateColumns: false,autoGenerateLayouts: false,mergeUnboundColumns: false, responseDataKey: 'Records', generateCompactJSONResponse: false, enableUTCDates: true, columns: [ { key: 'Id', headerText: 'Id', dataType: 'number' }, { key: 'Title', headerText: 'Title', dataType: 'string' }, { key: 'Authers', headerText: 'Authers', dataType: 'string' }, { key: 'publishYear', headerText: 'publishYear', dataType: 'string' }, { key: 'BasePrice', headerText: 'BasePrice', dataType: 'number' } ], features: [ { sortUrlKey: 'sort', sortUrlKeyAscValue: 'asc', sortUrlKeyDescValue: 'desc', columnSettings: [ { columnIndex: -1, allowSorting: false, columnKey: 'Id' } ], name: 'Sorting', mode: 'multiple' } ], localSchemaTransform: false });});</script>

代码如下;

index.cshtml

@using Infragistics.Web.Mvc
@model Infragistics.Web.Mvc.GridModel

<!-- Ignite UI Required Combined CSS Files -->
<link href="http://cdn-na.infragistics.com/igniteui/2015.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
<link href="http://cdn-na.infragistics.com/igniteui/2015.2/latest/css/structure/infragistics.css" rel="stylesheet" />
<script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>

@ Ignite UI必需的组合JavaScript文件 @          

@(Html.Infragistics().Grid(Model))


BookController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using BookStore.DAL;
using BookStore.Models;
using Infragistics.Web.Mvc;

namespace BookStore.Controllers
{
    public class BookController : Controller
    {
    private IBookRepository _bookRepository;
    public BookController()
    {
        this._bookRepository = new BookRepository(new BookContext());
    }
    public ActionResult Index()
    {
        var books = from BookStore in _bookRepository.GetBooks()
                    select BookStore;
        GridModel model = new GridModel();
        model.AutoGenerateColumns = false;

        GridColumn IdColumn = new GridColumn();
        IdColumn.Key = "Id";
        IdColumn.HeaderText = "Id";
        IdColumn.DataType = "number";

        GridColumn TitleColumn = new GridColumn();
        TitleColumn.Key = "Title";
        TitleColumn.HeaderText = "Title";
        TitleColumn.DataType = "string";

        GridColumn AuthersColumn = new GridColumn();
        AuthersColumn.Key = "Authers";
        AuthersColumn.HeaderText = "Authers";
        AuthersColumn.DataType = "string";

        GridColumn publishYearColumn = new GridColumn();
        publishYearColumn.Key = "publishYear";
        publishYearColumn.HeaderText = "publishYear";
        publishYearColumn.DataType = "string";

        GridColumn BasePriceColumn = new GridColumn();
        BasePriceColumn.Key = "BasePrice";
        BasePriceColumn.HeaderText = "BasePrice";
        BasePriceColumn.DataType = "number";

        model.Columns.Add(IdColumn);
        model.Columns.Add(TitleColumn);
        model.Columns.Add(AuthersColumn);
        model.Columns.Add(publishYearColumn);
        model.Columns.Add(BasePriceColumn);

        GridSorting sorting = new GridSorting();
        sorting.Mode = SortingMode.Multiple;

        ColumnSortingSetting colSetting = new ColumnSortingSetting();
        colSetting.ColumnKey = "Id";
        colSetting.AllowSorting = false;

        sorting.ColumnSettings.Add(colSetting);

        model.Features.Add(sorting);


        model.DataSource = books;
        return View(model);
    }


}
}

1 个答案:

答案 0 :(得分:0)

您似乎正在使用默认的MVC模板,默认情况下会在jQuery的末尾呈现_Layout.cshtml个软件包。只需删除它,因为您在视图中包含jQuery

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