在我的應用程序中,我在_LayoutPage.cshtml
中添加了一個導航欄。當我定義部分navbar
時,它將作爲部分視圖從_NavigationBar.cshtml
加載到每個視圖中。我還添加了引導3,工作正常,但我曾嘗試使用幾個圖標,因爲我曾嘗試將字體和自定義字形,在ASP.NET要麼加載頁面上停留沒有成功或者最終得到了錯誤:從Bootstrap添加自定義圖標會導致「堆棧溢出狀態」錯誤
Cannot evaluate expression because the current thread is in a stack overflow state
釷錯誤指出_NavigationBar.cshtml
在行
string userrole = Model != null ? Model.UserRoles.First() : string.Empty;
低於_NavigationBar.cshtml
的代碼是更改後。我所做的是我改了行:
<li>@Html.ActionLink("Home", "Index", "Home")</li>
到
<li><a href="@Html.Action("Index", "Home")"><span class="glyphicon glyphicon-home"></span></a></li>
它仍然是工作顯示導航欄上的圖標首頁。然而,當我嘗試從
<li>@Html.ActionLink("Login", "Login", "Account")</li>
改線46本
<a href="@Html.Action("Login", "Account")"><span class="glyphicon glyphicon-log-in"> Login</span></a>
頁停止加載的。
代碼_NavigationBar.cshtml
@using RaDAR_MVC4_EF6.ViewModels.Account
@model UserData
@{
string identityName = Model != null ? Model.UserName : string.Empty;
string userrole = Model != null ? Model.UserRoles.First() : string.Empty;
}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">RaDAR</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#radar-header-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="radar-header-collapse">
<ul class="nav navbar-nav">
<li><a href="@Html.Action("Index", "Home")"><span class="glyphicon glyphicon-home"></span></a></li>
<li>@Html.ActionLink("Patients", "Index", "Patients")</li>
<li>@Html.ActionLink("Applicants", "Index", "Applicants")</li>
<li>@Html.ActionLink("Applications", "Index", "Applications")</li>
<li>@Html.ActionLink("Accounts", "Index", "Account")</li>
</ul>
@if (Model != null)
{
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Signed as @identityName (@userrole)</a>
<ul class="dropdown-menu">
<li>@Html.ActionLink("Change password", "UpdatePassword", "Account", new { UserID = Model.UserID }, null)</li>
</ul>
</li>
<li>
@Html.ActionLink("Logout", "Logout", "Account", new { userName = identityName }, null)
</li>
</ul>
}
else
{
<ul class="nav navbar-nav navbar-right">
<li>
<a href="@Html.Action("Login", "Account")"><span class="glyphicon glyphicon-home"></span> Login</a>
</li>
</ul>
}
</div>
</div>
</nav>
代碼_Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="@Url.Content("~/Content/css/bootstrap.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/css/bootstrap-theme.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/StyleSheet.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-2.1.3.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/js/bootstrap.min.js")" type="text/javascript"></script>
<title>@ViewBag.Title</title>
</head>
<body>
@if (IsSectionDefined("navbar"))
{
@RenderSection("navbar")
}
<div class="container">
@RenderBody()
</div>
@if (IsSectionDefined("footer"))
{
<div class="container">
@RenderSection("footer")
</div>
}
</body>
</html>
您需要更改'的'to'' - 'Html.Action'正在調用服務器上的一個方法並返回一個結果(在你的情況下創建一個無限循環),而不是'Url.Action'呈現一個URL。 – 2015-02-09 10:03:04
@StephenMuecke一如既往的你是生命的救星:) 我覺得我需要一本適當的書通讀。謝謝 – Celdor 2015-02-09 10:08:52