0
我最近開始使用infragistics,我得到infragistics版本2013.2 ... 我正在創建一個項目使用mvc 4.0,並且我正嘗試使用igniteui組件...在這種情況下igGrid .. 是否有可能將數據源分配給實體框架?我看到顯示這種情況的YouTube視頻,但我收到錯誤。 什麼是最好的方式去使用實體框架模型或創建我自己的類?Infragistics IgniteUI網格集數據源(創建數據訪問類或使用實體框架)?
GridController
namespace MvcApplication5.Controllers
{
public class GridController : Controller
{
public MvcApplication5Context db = new MvcApplication5Context();
[GridDataSourceAction]
public ActionResult GetProducts()
{
return View(MvcApplication5.Models.ProductModel.GetProductList());
}
private DataTable GetCustomerDataTable()
{
SqlConnection conn = (SqlConnection)db.Database.Connection;
DataTable dt = new DataTable();
using (SqlConnection con = conn)
{
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Product", con))
{
adapter.Fill(dt);
}
}
return dt;
}
}
}
我的產品型號:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
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 ProductModel
{
public static IQueryable<Product> GetProductList()
{
MvcApplication5Context db = new MvcApplication5Context();
var Products = from c in db.Products
orderby c.ID
select c;
return Products.AsQueryable<Product>();
}
}
}
而我的看法;
@using Infragistics.Web.Mvc
@model IQueryable<MvcApplication5.Models.ProductModel>
@{
ViewBag.Title = "GetProducts";
}
<h2>GetProducts</h2>
@(Html.Infragistics().Grid<MvcApplication5.Models.ProductModel>()
.ID("grid1")
.Height("400px")
.Width("100%")
.AutoGenerateColumns(true)
.DefaultColumnWidth("150px")
.DataSource(Url.Action("GetProducts"))
.DataBind()
.Render()
)
我做了一些測試,我必須設法創建一個數據表,並將其綁定到iqGrid .. 的視頻分辨率低,我看不到最後一部分...
感謝提前...