从 Bootstrap 添加自定义图标会导致 "stack overflow state" 错误

Adding custom icons from the Bootstrap causes "stack overflow state" error

在我的应用程序中,我在 _LayoutPage.cshtml 中添加了一个导航栏。当我定义部分 navbar 时,它作为部分视图从 _NavigationBar.cshtml 加载到每个视图中。我还添加了 Bootstrap 3 ,效果很好,但我尝试使用一些图标,并且由于我尝试应用字体和自定义字形, ASP.NET 要么停留在加载页面上但没有成功,要么最终出现错误:

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>

它仍在工作,在导航栏中显示图标主页。但是,当我尝试从

更改第 46 行时
<li>@Html.ActionLink("Login", "Login", "Account")</li>

至此

<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>

@Html.Action() 在您的服务器上调用一个方法并 return 返回结果。在您的情况下,该结果是一个视图,其中包含 @Html.Action() 然后调用到 return 视图的另一个副本,其中包含 @Html.Action() 然后调用到 return视图的另一个副本等等,直到出现 Whosebug 异常。

你需要改变

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

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

这将生成一个 url