在一个网格Kendo UI中绑定更多表

时间:2014-03-20 09:41:35

标签: asp.net-mvc-4 razor kendo-ui grid kendo-grid

我有一个使用Kendo UI管理Sub-Categories的表格。现在,我想添加一个字段,为ProductNameProductID的每个产品创建一张新照片,但PhotoIdProductName位于另一个表格中。如何在一个网格中绑定两个或多个表?

控制器:

 public ActionResult Index()
        {
            var subcateViewModel = GetSubProduct();
            return View(subcateViewModel);
        }
        //Get SubCategory
        public ActionResult GetSub([DataSourceRequest] DataSourceRequest request)
        {
            return Json(GetSubProduct().ToDataSourceResult(request));
        }
private IEnumerable<SubCateViewModel> GetSubProduct()
        {
            var context = new AdvenDBEntities();
            var subcate = context.ProductSubcategories.Select(sub => new SubCateViewModel
                {
                    ProductSubcategoryID = sub.ProductSubcategoryID,
                    ProductCategoryID = sub.ProductCategoryID,
                    NameofBike = sub.NameofBike,
                    isSelected = sub.isSelected,
                });
            return subcate;
        }

是否有与此问题相关的示例?

1 个答案:

答案 0 :(得分:1)

Kendo Grid不会绑定到它绑定到对象的表,在本例中是ViewModel。在LinQ查询中,您将构建一个连接2个或更多表的语句。这样的事情。

public List<OrderGridViewModel> GetOrders()
    {
        using (var context = new TropicalServerEntities())
        {
            return (from cust in context.tblCustomer
                    join ord in context.tblOrder on cust.CustNumber equals ord.OrderCustomerNumber
                    select new OrderGridViewModel
                    {
                        TrackingNo = ord.OrderTrackingNumber,
                        RouteNo = (int)ord.OrderRouteNumber,
                        OrderId = ord.OrderID,
                        OrderDate = (DateTime)ord.OrderDate,
                        CustomerName = cust.CustName,
                        CustomerId = cust.CustID,
                        Address = cust.CustOfficeAddress1
                    }).Take(10).ToList();
        }
    }