2012-12-07 50 views
1

我嘗試在Telerik MVC Extension中創建Ajax支持分頁嵌套網格。我已經在瀏覽中呈現了嵌套網格,可以展開行Genre以顯示由GenreId過濾的相關相冊,但是當我爲此嵌套網格使用Ajax時,它在網格分頁中不起作用。我已經上傳了我的項目併發布了一些關於View和Controller的代碼。如何在Telerik MVC中創建Ajax支持分頁嵌套網格?

當我不使用ajax時,網格可以正常工作,但瀏覽重新加載時無法正確擴展,如何維護已擴展的行的狀態?

我很滿意任何幫助。

我的項目: http://share.vnn.vn/dl.php/11718146

我的視圖:

@{ 
    ViewBag.Title = "Home Page"; 
    Layout = @"~\Views\Shared\_Layout.cshtml"; 
} 

@(Html.Telerik().Grid<MvcMusicCodeFirsr.Models.Genre>(@Model) 
    .Name("personGrid") 
    .DataKeys(keys => keys.Add(k => k.GenreId)) 
    .DataBinding(d => d.Ajax().Update("_Update", "Home") 
    ) 
    // .Editable(editing => editing.Mode(GridEditMode.PopUp)) 
    .Columns(c => 
    { 
     c.Bound(m => m.Name).Width(150); 
     c.Bound(m => m.Description).Width(150); 
     //c.Bound(m => m.Birthdate); 
     c.Command(commands => 
     { 
      commands.Edit(); 
     }).Width(80); 
    }) 
    .DetailView(detailView => 
     detailView.Template(
     @<text> 
      @(Html.Telerik().Grid<MvcMusicCodeFirsr.Models.Album>(item.Albums) 
        .Name("Albums_" + item.GenreId) 
        .DataBinding(d => d.Ajax()) 
        .Columns(columns => 
        { 
         columns.Bound(o => o.Title).Width(101); 
         columns.Bound(o => o.Price).Width(140); 
        }) 
        .Pageable() 
        .Sortable() 
        .Filterable() 
      ) 

     </text> 
     ) 
     .ClientTemplate(
        Html.Telerik().Grid<MvcMusicCodeFirsr.Models.Album>() 

            .Name("Albums_<#=GenreId#>") 
            .DataBinding(d => d.Ajax()) 
            .Footer(false) 
            .ClientEvents(events => events.OnDataBinding("detailGrid_dataBinding")) 
            .ToHtmlString() 
     )) 

        .Sortable() 
        .Pageable() 


    ) 


) 

<script type="text/javascript"> 
    function detailGrid_dataBinding(e) { 
     var grid = $(this).data("tGrid"), 
      masterRow = $(this).closest("tr.t-detail-row").prev(), 
      dataItem = $("#Grid").data("tGrid").dataItem(masterRow); 

     grid.dataBind(dataItem.Albums); 

     e.preventDefault(); 

    } 
</script> 

我的控制器:

MusicStoreEntities db = new MusicStoreEntities(); 
    public ActionResult Index() 
    { 
     return View(db.Genres.ToList()); 
    } 

    [GridAction] 
    public ActionResult _Select() 
    { 
     return View(new GridModel (db.Genres.ToList())); 
    } 

    [GridAction] 
    public ActionResult _Update() 
    { 
     return View(new GridModel { Data = db.Genres.ToList() }); 
    } 

回答