0

私は最近インフラジスティックスを使い始めました。インフラジスティックス バージョン 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にバインドすることができました..ビデオは低解像度で、最後の部分を見ることができません...

前もって感謝します...

4

1 に答える 1

0

現在は機能していますが、違いは、ローカル db 接続を使用する代わりに、SQL サーバー データベースへの新しい接続を作成したことです。

于 2014-01-21T11:53:43.573 に答える