我刚开始用bootstrap学习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>
我的HomeController:
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();
}
我的观点: Index.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>
我遇到的问题是当导航栏出现时,我点击了主页,它在渲染体中显示主页或索引的内容就好了。 但是当我点击编程时,渲染体根本没有变化。
有人可以帮忙吗?
答案 0 :(得分:0)
感谢指点,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>