我正在学习 MVC 4,因此使用 razor 引擎来呈现我的视图。请多多包涵 :)
我有一个如下所示的导航菜单:
当用户单击其中一个导航菜单时,我希望有一个向下指向其内容的箭头。这是代码:
<li>
@Html.ActionLink("Business Intelligence", "Index", "Business_Intelligence")
@if ()
{
<span id="triangle">
<img src="~/Images/nav_arrow.png" />
</span>
}
</li>
<li>@Html.ActionLink("Marketing Services", "MarketingServices", "Marketing")</li>
现在,我想知道在 if 语句中写什么。我知道我需要将我的箭头链接到一个动作链接 - 像这样:
@if (@Html.ActionLink("Business Intelligence", "Index", "Business_Intelligence"))
{
<span id="triangle">
<img src="~/Images/nav_arrow.png" />
</span>
}
任何帮助,将不胜感激。谢谢你的时间。
PS:我的问题有意义吗?
这是我的看法:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="WebContent">
<nav>
<ul id="menu">
<li>
<a href="@Url.Action("Index", "Business_Intelligence")">
<img src="~/Images/myImage-Logo.png" />
</a>
@if (ViewContext.RouteData.Values["controller"] == "Business_Intelligence")
{
<span class="triangle">
<img src="~/Images/nav_arrow.png" />
</span>
}
</li>
<li>
@Html.ActionLink("Business Intelligence", "Index", "Business_Intelligence")
@if (ViewContext.RouteData.Values["controller"] == "Business_Intelligence")
{
<span class="triangle">
<img src="~/Images/nav_arrow.png" />
</span>
}
</li>
<li>@Html.ActionLink("Marketing Services", "MarketingServices", "Marketing")</li>
</ul>
</nav>
@RenderSection("featured", required: false)
@RenderBody()
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
<footer>
<p>Footer</p>
</footer>
</div>
</body>
和我的 CSS:
/* Images
-------------------------------------------------- ---------*/
.triangle{
display:block;
text-align: center;
}