Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
530
New to Infragistics IgniteUI ->error when attempting to follow Taz's example of how to use MVC +Entity Framework and igGrid
posted

So i am currently trying to find an answer to my problem..

I am following taz tutorial , and i am getting this error: the data source must implement IQueryable.

Here is my code:

Product Class

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;
using System.Web.Security;

namespace MvcApplication5.Models
{
public class Product
{
public int ID { get; set; }
public string ProductName { get; set; }
public Nullable<int> SupplierID { get; set; }
public Nullable<int> CategoryID { get; set; }
public string QuantityPerUnit { get; set; }
public Nullable<decimal> UnitPrice { get; set; }
public Nullable<short> UnitsInStock { get; set; }
public Nullable<short> UnitsOnOrder { get; set; }
public Nullable<short> ReorderLevel { get; set; }
public string SupplierName { get; set; }
public string CategoryName { get; set; }
public int Rating { get; set; }
public bool Discontinued { get; set; }
public string CategoryImageUrl { get; set; }
}
public class CustomerModel
{
public static IQueryable<Product> GetCustomerList()
{
MvcApplication5Context db = new MvcApplication5Context();

var customers = from c in db.Products
orderby c.ID
select c;

return customers.AsQueryable<Product>();

}

}

}

Grid Controller:

public MvcApplication5Context db = new MvcApplication5Context();
[GridDataSourceAction]
public ActionResult GetProducts()
{

return View(MvcApplication5.Models.CustomerModel.GetCustomerList());
}

View:

@using Infragistics.Web.Mvc
@model IQueryable<MvcApplication5.Models.Product>
@{
ViewBag.Title = "GetProducts";
}

<h2>GetProducts</h2>
@(Html.Infragistics().Grid(Model)
.ID("grid1")
.Columns(column =>
{
column.For(x => x.ID).DataType("string").HeaderText("Customer ID");
column.For(x => x.ProductName).DataType("string").HeaderText("Company Name");

})
.Height("400px")
.Width("100%")
.AutoGenerateColumns(true)
.DefaultColumnWidth("150px")

.DataSource(Url.Action("GetProducts"))
.DataBind()
.Render()
)

The difference is that in the tutorial it goes With EF database first, and i am going with EF codefirst..

Thanks for the help..