我正在學習MVC 4,因此使用剃刀引擎來渲染我的視圖。請多多包涵:)@ Html.ActionLink()if語句
我有一個導航菜單,看起來像這樣:
而且我希望有一個指向起伏朝其內容的箭頭,當用戶點擊導航中的一個菜單。這裏是代碼:
<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;
}
這有點複雜,你用if語句做什麼?你是否試圖找到是否有人點擊,徘徊,如果鏈接exsists? – Nomad101 2013-04-29 21:27:54
正確!我試圖弄清楚是否有人點擊菜單。 – Oliver 2013-04-29 21:45:21
好吧,這可以使用鏈接的onclick屬性來完成。您可以設置一個函數來在用戶點擊鏈接時調用,例如展開某物或隱藏另一個面板。 – Nomad101 2013-04-29 21:47:07