在正确的位置渲染局部视图 [英] Render Partial View in Correct Location

查看:96
本文介绍了在正确的位置渲染局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在尝试:将局部视图放置在telerik的选项卡中.

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.

我尝试过的事情:如果我使用RenderPage而不是RenderAction,则视图正确显示在Tabstrip内,但是不会调用控制器或为gridview加载模型.

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.

代码:

部分视图:

@model IEnumerable<MyModel>

@{
    ViewBag.Title = "Index";
}

@*My code to load a GridView*@

包含标签条的视图:

@{
    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>);                                 
          })
)

推荐答案

Kendo UI TabStrip的 Content 配置方法应用于静态"内容.静态的,我的意思是您已经拥有/知道的代码.要加载部分视图,最好使用 LoadContentFrom 配置方法.此方法需要现有Action的有效URL,该URL将返回目标部分视图:

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>);                                 
      })

)

这篇关于在正确的位置渲染局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆