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..
Hello Hugo,
Thank you for sharing your solution ! Please feel free to contact us if any further questions regarding binding the igGrid to EF arise.
I manage to resolve this problem, the solution was to create a real sql connection instead of using the local DB...
Hugo