2015-02-09 60 views
3

在我的應用程序中,我在_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> 

回答

1

@Html.Action()調用服務器上的方法,並返回結果。在你的情況下,這個結果是一個視圖,其中包含@Html.Action(),然後調用該視圖返回視圖的另一個副本,其中包含@Html.Action(),然後調用該視圖返回視圖的另一個副本,依此類推等等,直到獲得一個計算器例外。

您需要更改

<a href="@Html.Action("Login", "Account")"> 

<a href="@Url.Action("Login", "Account")"> 

這將生成一個URL