【问题标题】:Bootstrap tabs in layout.cshtml - not rendering bodylayout.cshtml 中的引导选项卡 - 不呈现正文
【发布时间】:2015-10-25 02:45:48
【问题描述】:

我刚刚开始使用引导程序学习 mvc。我已经设置了一个布局页面,如下所示:

<ul class="nav nav-tabs">
        <li class="active">@Html.ActionLink("HomE", "Index", "Home", null, new { @data_toggle = "tab", Href = "#Home" })</li>
        <li>@Html.ActionLink("ProgramminG", "Programming", "Home", null, new { @data_toggle = "tab", Href = "#Programming" })</li>
    </ul>

    <div class="tab-content">
        @RenderBody()
    </div>

我的家庭控制器:

public ActionResult Index()
    {
        ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

        return View();
    }
public ActionResult Programming()
    {
        ViewBag.Message = "Your Programming tab page";

        return View();
    }

我的观点: 索引.cshtml

    @{
    ViewBag.Title = "Home Page";
}

<div id="Home" class="tab-pane fade in active">
    <h3>HOME</h3>
    <p>This is from home view's index.cshtml.</p>
</div>

Programming.cshtml

    @{    
    ViewBag.Title = "Programming";    
}
    <div id="Programming" class="tab-pane fade">
        <h3>Programming</h3>
        <p>This is from home view's Programming.cshtml</p>
    </div>

我遇到的问题是,当导航栏出现时,我点击主页,它在渲染体中显示主页或索引的内容就好了。 但是,当我点击编程时,renderbody 根本没有改变。

有人可以帮忙吗?

【问题讨论】:

  • 为什么 Programming div 需要 tab-pane fade 类?
  • 您是否在编程动作上设置了断点以查看动作是否真正触发?
  • @artm。我正在关注stackoverflow.com/questions/22667368/how-to-use-bootstrap-tabs 的示例。这对我有用,所以我通过将选项卡放在布局页面中并使用 renderbody 希望通过单独的操作/cshtml 显示每个选项卡的内容来修改它
  • @Siamak。我刚刚测试,它没有触发。但是,当我手动将地址更改为 localhost:12345/Home/Programming 时,它触发了。我需要修改路线或类似的东西吗?
  • 看起来是真的!通过更改 ActionLink 和 Action 名称中的 Programming 名称并从 ActionLink 中删除类定义来测试它...

标签: asp.net-mvc twitter-bootstrap asp.net-mvc-4


【解决方案1】:

感谢 Siamak 和 artm 的指点。

以下修改解决了该问题:
修改过的actionlink

<ul class="nav nav-tabs">
    <li class="active">@Html.ActionLink("HomE", "Index", "Home")</li>
    <li>@Html.ActionLink("ProgramminG", "Programming", "Home")</li>
</ul>

<div class="tab-content">
    @RenderBody()
</div>

从视图中的 div 中删除了类

     @{    
    ViewBag.Title = "Programming";    
}
    <div id="Programming">
        <h3>Programming</h3>
        <p>This is from home view's Programming.cshtml</p>
    </div>

【讨论】:

    猜你喜欢
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 1970-01-01
    相关资源
    最近更新 更多