我最近开始使用 infragistics,我有 infragistics 版本 2013.2...我正在使用 mvc 4.0 创建一个项目,并且我正在尝试使用 igniteui 组件...在这种情况下为 igGrid.. 是否可以将数据源分配给实体框架?我看到了显示此案例的 youtube 视频,但我遇到了错误。最好的方法是什么,使用实体框架模型或创建我自己的类?
网格控制器
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 .. 视频分辨率低,我看不到最后一部分...
提前致谢...