调用控制器和方法时,Navbar图像不显示在MVC视图上

时间:2014-10-18 18:27:59

标签: asp.net-mvc model-view-controller view

问题背景:

我在MVC项目中使用书带完成了网站的开发。

问题:

如图所示,在运行网站并且明确键入主页[控制器] \索引[方法] 时,导航栏中的徽标会正确显示:

enter image description here

当输入返回其关联视图的控制器和方法名称时,在导航栏中显示徽标。

enter image description here

代码:

标题 - 包含导航栏 - 页脚在他们自己的cshtml文件名_Layout.cshtml中,可以使用@RenderBody方法创建的任何其他视图继承,如下所示:

  <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    <div class="navbar navbar-fixed-top">
        <nav class="navbar navbar-default" role="navigation" id="nav">
            <div class="container">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand"><img src="images/logo.png" alt="yourLogo"></a>
                </div>
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu<span class="caret"></span></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="#myCarousel">Projects</a></li>
                                <li><a href="#Welcome">Welcome</a></li>
                                <li><a href="#features">Workplace, Education, Development</a></li>
                                <li><a href="#About">About Me</a></li>
                                <li><a href="#Location">Location</a></li>
                                <li><a href="#Contact">Contact Me</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="container body-content">
        @RenderBody()
    </div>
    <footer>
        <div class="container">
            <div class="row">
                <div class="col-sm-12 textAlignCenter">
                    <h5>Copyright &copy; 2014</h5>
                </div>
            </div>
        </div>
    </footer>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</body>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</html>

任何帮助确定徽标不会显示的原因都将受到赞赏。

1 个答案:

答案 0 :(得分:1)

将您的图片路径更改为相对的,

<a class="navbar-brand"><img src="@Url.Content("~/images/logo.png")" alt="yourLogo"></a>