[英]kendo grid in kendo tabs using partial view
出於某種原因,盡管GetAllProductList返回記錄,但我仍可以獲取第二個選項卡(產品詳細信息)以將記錄綁定到網格中。 請指教,謝謝
index.cshtml主頁/Index.cshtml
@(Html.Kendo().TabStrip()
.Name("tabstrip")
.Items(items =>
{
items.Add().Text("Search")
.LoadContentFrom("Index", "ProductDetails")
.Selected(true);
items.Add().Text("Product Details")
.LoadContentFrom("_ProductData", "ProductDetails")
})
)
產品詳細/ Index.cshtml
@(Html.Kendo()。網格()
.Name("BookGrid")
.HtmlAttributes(new { @Style = "align:center; font-size:10px; width:950px" })
.Columns(columns =>
{
columns.Bound(p => p.BookId).Width(95);
columns.Bound(p => p.Name).Width(120);
})
.ToolBar(toolbar => toolbar.Create())
.Sortable()
//.Pageable()
.Pageable(paging => paging
.Input(false)
.Numeric(true)
.PreviousNext(true)
.PageSizes(new int[] { 5, 10, 25, 50 })
.Refresh(false)
)
.Selectable()
.Scrollable()
.ColumnMenu(c => c.Columns(false))
.DataSource(dataSource => dataSource
.Ajax()//bind with Ajax instead server bind
.PageSize(10)
.ServerOperation(true)
.Model(model =>
{
model.Id(p => p.BookId);
})
.Sort(sort => sort
.Add(x => x.Name).Descending())
.Read(read => read.Action("GetBookData", "ProductDetails").Type(HttpVerbs.Get))
)
)
ProductDetails / _ProductData.chtml(部分頁面)
@(Html.Kendo().Grid<HH.PrductModel>()
.Name("ProductGrid")
.HtmlAttributes(new { @Style = "align:center; font-size:10px; width:950px" })
.Columns(columns =>
{
columns.Bound(p => p.ProductId).Width(95);
columns.Bound(p => p.Name).Width(120);
})
.ToolBar(toolbar => toolbar.Create())
.Sortable()
//.Pageable()
.Pageable(paging => paging
.Input(false)
.Numeric(true)
.PreviousNext(true)
.PageSizes(new int[] { 5, 10, 25, 50 })
.Refresh(false)
)
.Selectable()
.Scrollable()
.ColumnMenu(c => c.Columns(false))
.DataSource(dataSource => dataSource
.Ajax()//bind with Ajax instead server bind
.PageSize(10)
.ServerOperation(true)
.Model(model =>
{
model.Id(p => p.ProductId);
})
.Sort(sort => sort
.Add(x => x.Name).Descending())
.Read(read => read.Action("GetProductData", "ProductDetails").Type(HttpVerbs.Get))
)
)
**ProductDetailscontroller**
public ActionResult Index()
{
return View();
}
///Display for tab 1
public ActionResult GetBookData ([DataSourceRequest] DataSourceRequest request)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
return Json(GetAllBookList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
private static IEnumerable<BookModel> GetAllBookList()
{
using (var dc = new HHEntities())
{
var result = (from a in dc.Books
select new BookModel
{
BookId= a.BookId,
Name= a.Name
});
return result.Distinct().ToList();
}
}
///Display for tab 2
public ActionResult GetProductData([DataSourceRequest] DataSourceRequest request)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
return Json(GetAllProductList().ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
以下將返回記錄,但由於某些原因,它將綁定到“產品詳細信息”選項卡中的網格
/// <summary>
/// </summary>
/// <returns></returns>
private static IEnumerable<ProductModel> GetAllProductList()
{
using (var dc = new HHEntities())
{
var result = (from a in dc.Products
select new ProductModel
{
ProductId= a.ProductId,
Name= a.Name,
Description= a.Description,
ExpiryDate= a.ExpiryDate
});
return result.Distinct().ToList();
}
}
public ActionResult __ProductData()
{ return PartialView();}
我懷疑問題在於兩個網格都使用相同的HTML id屬性(通過Name()
方法設置)呈現。 您需要給網格指定唯一的名稱。 例如,您可以在操作方法的ViewData
中放置一些索引,這些方法將呈現包含網格的部分視圖。 然后在局部視圖本身中使用該索引,以使網格名稱唯一:
@(Html.Kendo().Grid<HH.PrductModel>()
.Name("Product" + ViewData["index"])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.