我最近开始使用infragistics,我有了infragistics版本2013.2 ... 我正在使用mvc 4.0创建一个项目,我正在尝试使用igniteui组件......在这种情况下是igGrid .. 是否可以将数据源分配给实体框架?我看到显示这种情况的youtube视频,但我收到了错误。 什么是最好的方法,使用实体框架模型或创建我自己的类?
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 .. 视频分辨率很低,我看不到最后一部分......
提前感谢...
答案 0 :(得分:0)
现在可以使用,区别在于使用本地数据库连接,而是创建了与sql server数据库的新连接。