Render Partial View in Correct Location

心已入冬 提交于 2019-12-12 04:48:35

问题


Trying to: Place a partial view within a telerik tabstrip.

Problem: The view is being displayed above the tab strip instead of within the first tab.

What I have tried: If I use RenderPage instead of RenderAction then the view correctly appears inside the tabstrip however then the controller does not get called or load the model for the gridview.

Code so far:

Partial View:

@model IEnumerable<MyModel>

@{
    ViewBag.Title = "Index";
}

@*My code to load a GridView*@

View containing tab strip:

@{
    ViewBag.Title = "MyView";
}


@(Html.Kendo().TabStrip()
          .Name("tabstrip")
          .Items(tabstrip =>
          {
              tabstrip.Add().Text("Index")
                  .Selected(true)
                  .Content(@<text>
                    @{Html.RenderAction("Index", "MyController");}
                </text>);
              tabstrip.Add().Text("Index2")
                  .Content(@<text>
                </text>);                                 
          })
)

回答1:


The Content configuration method of a Kendo UI TabStrip should be used for "static" content. By static I mean code that you already have/know. For loading partial views it is best to use the LoadContentFrom configuration method. This method requires a valid URL of an existing Action, which returns the targeted partial view:

@(Html.Kendo().TabStrip()
      .Name("tabstrip")
      .Items(tabstrip =>
      {
          tabstrip.Add().Text("Index")
              .Selected(true)
              .LoadContentFrom(Html.Action("Index", "MyController"));
          tabstrip.Add().Text("Index2")
              .Content(@<text>
            </text>);                                 
      })

)



来源:https://stackoverflow.com/questions/25946346/render-partial-view-in-correct-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!