How to Put Elses If in Layout

Asked

Viewed 38 times

0

Ola, I am trying to put in ifs layout in order to change login to logout but it is not working. In Layout I have this code :

@using Microsoft.AspNetCore.Http;
@using WebApplication1.Controllers;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - WebApplication1</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />
<link href="~/lib/jqueryui/jquery-ui.css" rel="stylesheet" />
</head>
<body>
<header>
    <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark border-bottom box-shadow mb-3">
        <div class="container">
            <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index"> </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                    aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
                <ul class="navbar-nav">
                    @if (SociosController.estaAutenticado(Context))
                    {
                        <li class="nav-item">
                            <p class="nav-link text-dark">Bem-vindo @Context.Session.GetString("Nome")!</p>
                        </li>
                        <li class="nav-item">
                            <form class="form-inline" asp-controller="Home" asp-action="Logout">
                                <button type="submit" class="nav-link btn btn-link text-white">Sair</button>
                            </form>
                        </li>
                    }

                    @else if(ProfessoresController.estaAutenticado(Context))
                    {
                        <li class="nav-item">
                            <p class="nav-link text-dark">Bem-vindo @Context.Session.GetString("Nome")!</p>
                        </li>
                        <li class="nav-item">
                            <form class="form-inline" asp-controller="Home" asp-action="Logout">
                                <button type="submit" class="nav-link btn btn-link text-white">Sair</button>
                            </form>
                        </li>
                    }

                    @else if(AdministradoresController.estaAutenticado(Context))
                    {
                        <li class="nav-item">
                            <p class="nav-link text-dark">Bem-vindo @Context.Session.GetString("Nome")!</p>
                        </li>
                        <li class="nav-item">
                            <form class="form-inline" asp-controller="Home" asp-action="Logout">
                                <button type="submit" class="nav-link btn btn-link text-white">Sair</button>
                            </form>
                        </li>
                    }
                    else
                    {
                        <li class="nav-item">
                            <a class="nav-link text-white" asp-controller="Home" asp-action="Login">Entrar </a>
                        </li>
                    }
                </ul>

                <ul class="navbar-nav flex-grow-1">
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Index">Pagina Inicial</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Info">Sobre nós</a>
                    </li>


                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="AulasDeGrupo">Aulas de Grupo</a>
                    </li>


                    <li class="nav-item" style="text-align:right">
                        <a class="nav-link text-white"  asp-area="" asp-controller="Home" asp-action="Registo">Registar</a>
                    </li>

                </ul>
            </div>
        </div>
    </nav>
</header>
<div class="container">
    <main role="main" class="pb-3">
        @RenderBody()
    </main>
</div>

<footer class="border-top footer text-muted">
    <div class="container">
        <p style="color:white">

            Quinta de Prados, 5001-801 Vila Real
            <abbr title="Phone"> </abbr>
            <i style='font-size:24px' class='fas'>&#xf879;</i>
            259 345 125

            |    Horário De Funcionamento: 8:30 h ás 13:30h, 15:00h ás 22:00h, Segunda a Sexta
            <br />
            e-mail:
            <i class="material-icons">&#xe0be;</i>
            <a href="[email protected]">[email protected]</a><br />

        </p>
    </div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/jqueryui/jquery-ui.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@RenderSection("Scripts", required: false)

Can someone help me fix this? He presents these errors: inserir a descrição da imagem aqui

  • Managed to make it work?

  • @tvdias yes thank you

1 answer

1


It is necessary to change @else if for else if.

Ex: https://www.w3schools.com/asp/showfile_c.asp?filename=try_razor_cs_012

@{var price=25;}
<html>
<body>
@if (price>=30)
    {
    <p>The price is high.</p>
    }
    else if (price>20 && price<30) 
    {
    <p>The price is OK.</p>
    }
    else
    {
    <p>The price is low.</p>
    }
</body>
</html>

Browser other questions tagged

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