我是ASP.NET新手,我想弄清楚如何創建具有下拉功能的導航欄菜單項。我特別使用this主題。在他們的示例代碼中,他們演示了下拉功能,但是在我的默認MVC應用程序中,我使用_Layout.cshtml創建了我的導航欄。我很難弄清楚正確的語法。如何在ASP.NET中的Layout.CSHTML中創建下拉導航欄菜單項
我已在我的Index.cshtml頁面中實現了section
s,我希望第一個導航欄菜單項下拉菜單能夠相應地執行。我怎麼能做到這一點?
Index.cshtml
<section id="item 1">...</section>
<section id="item 2">...</section>
<section id="item 3">...</section>
_Layout.cshtml
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("My Application", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
@*<li>@Html.ActionLink("Index", "Index", "Home")</li>*@
<li class="dropdown">
<a class="dropdown-toggle" role="button" aria-expanded="false" data-toggled="dropdown">@Html.ActionLink("Home", "Index", "Home")</a>
<ul class="dropdown-menu" role="menu">
<li>Action 1</li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
</ul>
</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</div>
</div>
提前感謝!
編輯:
我已經更新了我_Layout.cshtml它顯示的下拉和列表項做導航到我的索引頁,但在這裏,我怎麼能具體指導各列表項指向的每個部分Index.cshtml頁面(即item 1
,item 2
,或item 3
?
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("My Application", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
@*<li>@Html.ActionLink("Index", "Index", "Home")</li>*@
<li class="dropdown">
<a class="dropdown-toggle" role="button" aria-expanded="false" href="#" data-toggle="dropdown">Home <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li>@Html.ActionLink("Item 1", "Index", "Home", null, new { id = "item 1" })</li>
<li>@Html.ActionLink("Item 2", "Index", "Home", null, new { id = "item 2" })</li>
<li>@Html.ActionLink("Item 3", "Index", "Home", null, new { id = "item 3" })</li>
</ul>
</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</div>
</div>
這裏是另一個link我引用。
我爲HomeController.cs
public ActionResult Index()
{
return View();
}
切換按鈕是錯誤的(您正在超鏈接中創建一個超鏈接),但否則這看起來或多或少是正確的。那麼,你有什麼麻煩? –
好吧,我已經爲我的HomeController的Index ActionResult註釋掉了原始的HTML Helper。我只是想爲我的索引導航欄項目創建一個下拉列表,其中包含三個文本項目,在選擇時,我將導航到該頁面的該部分。我是否需要更新我的HomeController的Index ActionResult,或者我可以以某種方式放置#1,#2或#3,以便每個部分都可以正確導航? – Matthew