我有一个使用Kendo UI管理Sub-Categories
的表格。现在,我想添加一个字段,为ProductName
,ProductID
的每个产品创建一张新照片,但PhotoId
和ProductName
位于另一个表格中。如何在一个网格中绑定两个或多个表?
控制器:
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;
}
是否有与此问题相关的示例?
答案 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();
}
}