2013-04-18 87 views
0

MVC 4.當我在Kendo UI PanelBar中放置Grid時,它無法按預期工作。該視圖最終不會將Grid放在Content()中,而是將其本身永久地放入面板recursively中。MVC的Kendo UI:在PanelBar中渲染網格

@(Html.Kendo().PanelBar() 
    .Name("IntroPanelBar") 
    .Items(items => 
     { 
      items.Add() 
       .Text("papering Reports") 
       .Selected(true) 
       .Expanded(true) 
       .Content(() => Html.RenderAction("Grid")); 

要看看它是否是我的代碼,我把電網PanelBar之外,一切都呈現與PanelBar外網格精細:

@{ 
    Html.RenderAction("Grid"); 
} 

@(Html.Kendo().PanelBar() 
    .Name("IntroPanelBar") 
    .Items(items => 
     { 
      items.Add() 
       .Text("papering Reports") 
       .Selected(true) 
       .Expanded(true) 
       .Content("PLAIN TEXT"); 
+0

您的「網格」操作是否需要在控制器上進行自己的操作?你在別處使用它還是僅在此面板中使用?如果僅在此面板中使用它,則可以考慮將網格視圖代碼直接放入此視圖中。我現在的猜測是,當你在面板的內容中包含網格時,你需要在網格上調用.ToClientTemplate(),而你的視圖並沒有這樣做。 – Nathan

+0

網格在其他地方使用,在這種情況下也是局部視圖。儘管我找到了解決方案。我應該使用'.Content(Html.Action(「Grid」)。ToHtmlString());'而不是'.Content(()=> Html.RenderAction(「Grid」)); 「 –

回答

2

的解決方案是使用MVCHtmlString輸出的行動,而不是:

@(Html.Kendo().TabStrip() 
    .Name("tabstrip") 
    .Items(tabstrip => 
     { 
      tabstrip.Add().Text("papering") 
        .Selected(true) 
        .Content(Html.Action("Grid").ToHtmlString()); <--- 
2

我知道這是一個較老的問題,但當我搜索到類似的問題時彈出。這可以通過使用Razor helper function來解決。我的例子顯示了一個帶有包含網格的標籤條的面板。

<div id="panel"> 
    @(Html.Kendo().PanelBar() 
     .Name("panelbar") 
     .ExpandMode(PanelBarExpandMode.Single) 
     .Items(panelbar => 
      { 
       foreach (var a in Model) { 

        panelbar.Add().Text(a.dom.fileName) 
         .Content(@<div id="tabs"> 
          @RenderTabStrip(a) 

         </div> 
       ); 

       } 
      }) 
    ) 

    @helper RenderTabStrip(DominguezReport.WebInterface.Models.accModelTest a) 
{ 
    @(Html.Kendo().TabStrip() 
     .Name("tabs" +a.dom.recordID) 
     .Items(tabstrip => 
     { 
      tabstrip.Add() 
       .Text("Status") 
       .Content(@<div>@RenderStatusGrid(a)</div>); 

      tabstrip.Add() 
       .Text("Errors") 
       .Content(@<div>@RenderErrorGrid(a)</div>); 
     }) 
    ); 
} 

    @helper RenderStatusGrid(DominguezReport.WebInterface.Models.accModelTest a) 
{ 
    @(Html.Kendo().Grid(a.drs) 
    .Name("Status") 
    .Columns(columns=> 
        { 
         columns.Bound(c => c.currentStatus); 
         columns.Bound(c => c.updateTime); 
        }) 
        .Scrollable() 
    ) 
} 
    @helper RenderErrorGrid(DominguezReport.WebInterface.Models.accModelTest a) 
{ 
    @(Html.Kendo().Grid(a.dre) 
    .Name("Errors") 
    .Columns(columns => 
    { 
     columns.Bound(c => c.errorType); 
     columns.Bound(c => c.errorDetail); 
     columns.Bound(c => c.updateTime); 
    }) 
    .Scrollable() 
) 
} 
0

我試了下面的代碼,它的工作。在PanelBar的內容部分,將網格代碼封裝在<div>標籤中。

@(Html.Kendo().PanelBar() 
.Name("panelbar") 
.ExpandMode(PanelBarExpandMode.Single) 
.Items(panelbar => 
    { 
      panelbar.Add().Text("Devices") 
      .Expanded(true) 
      .Content(@<div>@(Html.Kendo().Grid(Model) 
      ...grid code here 
      </div> 
      ); 
      }) 
      )