2013-04-25 41 views
1

出於某種原因,我可以通過GetAllProductList返回記錄來獲得第二個選項卡(產品詳細信息)綁定網格中的記錄。請指教,謝謝kendo使用局部視圖的kendo標籤網格

index.cshtml HOME/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();} 
+0

問題又出現了什麼問題?你說你可以綁定網格。 – 2013-04-25 11:13:25

+0

它只是顯示空格子。這真的很奇怪。即使當我從GetAllProductList檢查var結果顯示記錄。謝謝 – Spidey 2013-04-25 13:14:53

回答

1

我懷疑的問題是,這兩個網格具有相同呈現HTML id屬性(通過Name()方法設置)。你需要給你的網格獨一無二的名字。例如,您可以在渲染包含網格的局部視圖的操作方法中放置ViewData中的一些索引。然後在局部視圖中使用該索引本身以使網格名稱唯一:

@(Html.Kendo().Grid<HH.PrductModel>() 
     .Name("Product" + ViewData["index"]) 
+0

嗨Atanas,謝謝,我會嘗試 – Spidey 2013-04-25 15:54:04

+0

嗨Atanas,我修改了代碼。你會不會建議。謝謝 – Spidey 2013-04-29 16:32:35

+0

我沒有看到你的代碼改變了網格的Name()。試試看。此外,爲什麼第一個標籤加載整頁而不是局部視圖? – 2013-04-29 19:03:46