SO私は次のように製品と呼ばれるエンティティがあります。私のコントローラのアクションで次にどのようにasp.net mvcでdatatablesを実装するには?
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();
public IEnumerable<Product> Products
{
get { return context.Products; }
}
}
Index
私:私は、次のようIProductRepository
と呼ばれる別のクラスから派生しEFProductRepository
と呼ばれる別のクラスを持っている
public class Product
{
[HiddenInput(DisplayValue=false)]
public int ProductID { get; set; }
public string ProductName { get; set; }
[DataType(DataType.MultilineText)]
public string ProductDescription { get; set; }
public decimal ProductPrice { get; set; }
public string Category { get; set; }
public string SubCategory { get; set; }
}
をこれを持っている:
public ViewResult Index()
{
return View(repository.Products);
}
テーブル内では、だから、どうすればこのコードにDataTableクライアント側を実装できますか?私はここでこれを試したjQuery Datatable with MVC 5 and Entity Frameworkしかし、残念なことに運がない。 助けていただければ幸いです。
datatableプラグインはJSON形式のデータを想定しています。 context.ProductsをJSON形式に変換する(プラグインが探しているプロパティを持つビューモデルのリストにマッピングした後かもしれない) – Shyju
@Shyju JSONに変更する方法についてのヒント? –
あなたが使うことができる 'Controller.Json'メソッドがあります。 – Shyju