Layout does not appear in "_layout.cshtml"

Asked

Viewed 520 times

1

I’m editing the _layout.cshtml file so it can be replicated on the other pages.

However, when I run my program it’s like I haven’t made any changes to the layout.

What can it be?

By the way I’m having the same mistake:

The name 'Scripts' does not exist in the Current context", this error prevents me from seeing my layout? from testing it?

My Layout is ugly and without any modification!

<!DOCTYPE html>
<html lang="pt-BR">
    <head>
        <meta charset="utf-8" http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>PROJECT</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Scripts.Render("~/bundles/modernizr")
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/bundles/jqueryui")
        <script type="text/javascript" src="@Scripts.Url("~/scripts/jquery-extensions.js")" ></script>
        <script type="text/javascript" src="@Scripts.Url("~/scripts/jquery.min.js")"></script>
        <link rel="Stylesheet" href="~/Content/themes/base/jquery.ui.all.css" type="text/css" />
        @RenderSection("scripts", required: false)
        @Styles.Render("~/Content/css")

<head>
<body>
<header>
    <div id="body_principal">
        <div>
            <div id="cabecalho">
                <a href="@Url.Action("Index", "Home")">
                    <img alt="" src="@Url.Content("~/content/images/fundo_cabecalho.png")" width="200" height="100"/></a>
                <div id="vision">
                <div id="logo">
                <a href="@Url.Action("Index", "Home")">
                    <img alt="" src="@Url.Content("~/content/images/logo_header.png")" width="337" height="92" /></a>
                <div id="status">
                    <table border="0" cellspacing="0" cellpadding="0">
                        <tr><img src="@Url.Content("~/content/images/fundo_status_01.png")" width="99" height="34" /></tr>
                    </table>
                </div>
                <div>
                    @Html.Action("Switch", "Vision")
                </div>
                    <div id="user">
                        @User.Data.Name
                    </div>
                <div id="icones">
                        <img alt="@User.Data.Name" src="@Url.Content("~/Content/images/16/ico_user.gif")" align="middle" />
                    </div>
                    </div>
                    </div>
            </div>

     </header>
    <div id="conteudo">
                <div id="conteudo-principal">
                    <div id="barra-lateral">
                        <img src="@Url.Content("~/Content/images/pixel.gif")" height="1" width="1" />
                        <div id="menu_lateral">
                            @Html.Action("Menu", "Vision")
                        </div>
                    </div>
                    <div id="principal">
                        <img src="@Url.Content("~/Content/images/pixel.gif")" height="1" width="1" />
                        <div id="titulo">
                            @this.ViewBag.Title @(this.ViewBag.SubTitle == null ? string.Empty : " / ")
                            <span id="subtitulo">@this.ViewBag.SubTitle</span>
                        </div>
                        <div class="clear"></div>
                        <div id="content">@this.RenderBody()</div>
                        @RenderSection("featured", required: false)
                    </div>
                </div>
            </div>
        </div>

    <div id="console"></div>
    <script type="text/javascript" src="@Scripts.Url("~/Scripts/jquery.unobtrusive-ajax.min.js")" ></script>
</body>
</html>

SS

SS

  • In your Views you are referencing the Layout? @{&#xA; Layout = "~/Views/Shared/_Layout.cshtml";&#xA;}

  • Yeah, that’s not it!

  • You can put the layout code in your question?

  • put up.

  • Which line the compiler points to the error?

  • I posted the image above

  • This project seems to be completely disfigured. How are the project References?

Show 2 more comments

1 answer

1

Here is the mistake:

<script type="text/javascript" src="@Scripts.Url("~/Scripts/jquery.unobtrusive-ajax.min.js")" ></script>

There is no @Scripts.Url. Probably you tried to use intuitively.

Simply use:

<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>

Another thing to check is if the dynamic libraries are registered in Razor. Check inside the file web.config inside the directory Views (attention here because there are two files web.config within the project) if there is a configuration section with the following:

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
  • I left it as you suggested, still wrong.. by the way I am with the errors so: "The name 'Scripts' does not exist in the Current context", this error prevents me from seeing my layout? how can I fix? libraries are being used correctly

  • @Thamirescunha It is problem of configuration of your project. I am editing.

  • Morrison posted another image.. see these settings are already there. It’s really challenging to find out the cause of these errors..

Browser other questions tagged

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