【发布时间】:2016-04-12 15:45:24
【问题描述】:
所以我有一个名为 product 的实体,如下所示:
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; }
}
我有另一个名为 EFProductRepository 的类,它派生自另一个名为 IProductRepository 的类,如下所示:
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();
public IEnumerable<Product> Products
{
get { return context.Products; }
}
}
然后在我的控制器操作Index 我有这个:
public ViewResult Index()
{
return View(repository.Products);
}
还有一个列出表中数据的索引视图,所以问题是我如何在这段代码中实现 DataTable 客户端?我在这里尝试过jQuery Datatable with MVC 5 and Entity Framework,但不幸的是没有运气。 任何帮助表示赞赏,问候。
【问题讨论】:
-
我假设数据表插件需要 JSON 格式的数据。将您的 context.Products 转换为 JSON 格式(可能是在将它们映射到具有插件正在寻找的属性的视图模型列表之后)
-
@Shyju 关于如何将其更改为 JSON 的任何提示?
-
您可以使用
Controller.Json方法。
标签: jquery asp.net-mvc datatables-1.10