How to replicate the same image in the header? C# Asp.Net

Asked

Viewed 47 times

0

I am trying to replicate the same image in the header of all pages, but it appears broken. What can it be? It is a program done in c#, Asp.net. I already searched but could not fix. From what I understand, it is some problem in the file _Layout.cshtml, which is in the folder Shared. Look at the situation:

The image is in the Images folder, which I put inside in the View/Shared folder. It follows the code of the _Layout.cshtml file:

<!DOCTYPE html>
<script src="~/Scripts/Js.js"></script>
<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-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("Cooperativa de Médicos do DF", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse text-right">
                <ul class="nav navbar-nav ">
                    <li>@Html.ActionLink("Sair", "Index", "Home")</li>
                     <img src="images/icone.png" id= "simbolo" alt="símbolo dos médicos"/>
                </ul>
            </div>
        </div>
    </div>

    <div class="container body-content">
        @RenderBody()
        <br /><br /><br /><br /><br /><br /><br /><br />
        <hr />           
        <footer class="text-center">
            <p>&copy; @DateTime.Now.Year - Cooperativa de Médicos do DF</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/inputmask")
    @RenderSection("scripts", required: false)
</body>
</html>

inserir a descrição da imagem aqui

1 answer

0

The path of the image is wrong, the way it is will always seek from the relative path

<img src="images/icone.png">

What you need is that, despite the route, it is directed in the absolute path or from the root of the application. The prefix ~/ will let Asp.net solve this path for you.

<img src="~/images/icone.png">

And keep the image file on wwwroot\images, because this is the right place for her.

  • Hello, Leandro! When I do this, the image of the home page that was showing, also does not open.

  • You left the file on wwwroot/images?

  • @Kakatakeda Where is your directory images

Browser other questions tagged

You are not signed in. Login or sign up in order to post.