2012-11-02 53 views
0

當頁面加載時,我的嵌套模板列未出現在我的標記中。我正嘗試在另一個父網格的DetailView中加載一個帶有模板列的網格。我可以看到我的數據被傳遞,顯然UnitPeriod的「名稱」出現,但我的模板列中沒有任何內容,所以看起來數據正在傳遞到網格中。我用firebug檢查了源代碼,並且該列始終爲空。任何1可以找到原因嗎?Telerik Grid中的DetailView中的模板列MVC

<div> 
@(Html.Telerik().Grid<RentableUnit>() 
    .Name("RentableUnits") 
    .Columns(columns => 
    { 
     columns.Bound(e => e.UnitID).Hidden(); 
     columns.Bound(e => e.Name).Width(75); 
    }) 
    .ClientEvents(events => events.OnRowDataBound("employees_onRowDataBound") 
          .OnDetailViewExpand("unit_onDetailViewExpand") 
          .OnDetailViewCollapse("unit_onDetailViewCollapse")) 
    .DetailView(details => details.ClientTemplate(
     Html.Telerik().Grid<UnitPeriod>() 
      .Name("UnitPeriod_<#= UnitID #>") 
      .Columns(columns => 
       { 
        columns.Bound(o => o.Name); 
        columns.Template(@<text> 
        @foreach (Day day in item.Days) 
        { 
         if (!day.IsRentable) 
         { 
          <img src="../../Content/Images/Houses/icon_lokad.png"/> 
         } 
         else 
         { 
          <img src="../../Content/Images/Houses/icon_opid.png"/> 
         } 
        } 
      </text>); 
      }) 
      .ClientEvents(events => events.OnRowDataBound("orders_onRowDataBound")) 
      .DataBinding(dataBinding => dataBinding.Ajax() 
      .Select("SelectedUnitPeriod", "Home", new { unitId = "<#= UnitID #>" })) 
      .ToHtmlString() 
    )) 
    .DataBinding(dataBinding => dataBinding.Ajax().Select("RentableUnits", "Home")) 
    .Sortable() 
    ) 
</div> 

<script type="text/javascript"> 
    var derpinski = ""; 
    function expandFirstRow(grid, row) { 
     if (grid.$rows().index(row) == 0) { 
      grid.expandRow(row); 
     } 
    } 

function loadTabGridContent(e) { 
    var url = '/Home/TabGridContent/'; 
    $.ajax({ 
     type: 'GET', 
     dataType: 'html', 
     url: url, 
     success: function (data) { 
      alert('success'); 
      $('#TabGridContent').html(data); 
     } 
    }); 
} 

function employees_onRowDataBound(e) { 
    var grid = $(this).data('tGrid'); 
    expandFirstRow(grid, e.row); 
} 

function orders_onRowDataBound(e) { 
    var grid = $(this).data('tGrid'); 
    expandFirstRow(grid, e.row); 
} 

function unit_onDetailViewExpand(e) { 
    var mstRow = e.masterRow; 
    var unitNumber = mstRow.cells[1].innerHTML; 
    derpinski = derpinski + unitNumber + ","; 
} 

function unit_onDetailViewCollapse(e) { 
    var mstRow = e.masterRow; 
    var unitNumber = mstRow.cells[1].innerHTML; 
    derpinski = derpinski.replace(unitNumber + ",", ""); 
} 

回答

0

我發現這是不可能的嵌套網格。

我最終在我的自定義類中創建了一個字符串變量,並在Telerik網格中使用了Bound機制,並對網格中的html字符串進行了編碼。這不是最漂亮的解決方案,但它的運作情況儘可能符合我的需求。

事情是這樣的:

[GridAction] 
public ActionResult SelectedUnitPeriod(int unitId, string startDate) 
{ 
    // Some stuff (just to abbreviate 
    unitPeriodName = ""; // Created the row as string 
    daystr = "";   // also with this one 
    rentableUnitPeriods.Add(new RentableUnitPeriod(unitPeriod.UnitId, unitPeriodName, dayStr, unitPeriod.PrimaryImg)); 
    return View(new GridModel(rentableUnitPeriods)); 
} 

這是沒有的伎倆對我來說:)