ASP.NET MVC Error when identifying style file

Asked

Viewed 127 times

1

I posted a website that is at MVC4 at this address. http://acensao-com-br.umbler.net/Login

While trying to access I get this error message:

"Value cannot be null or Empty. Parameter name: contentPath"

Line where error occurs:

@RenderSection("Styles", required: false)

What is the reason for this mistake?

The site works normally in a local environment.

This Section is declared on only a few pages that may have other optional style files.

@section Styles {
    @Styles.Render("~/styles/chosen")
    @Styles.Render("~/styles/datetimepicker")
}

Hence it is marked in the _Layout.cshtml file as "required: false"

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title</title>
    @Styles.Render("~/styles/css")
    @Scripts.Render("~/bundles/modernizr")

    @RenderSection("Styles", required: false)
</head>

Buddleconfig

public static void RegisterBundles(BundleCollection bundles)
        {
            //JS

            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate.js"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new ScriptBundle("~/bundles/mask").Include(
                        "~/Scripts/jquery.mask.js"));

            bundles.Add(new ScriptBundle("~/bundles/maskMoney").Include(
                        "~/Scripts/jquery.maskMoney.min.js"));

            bundles.Add(new ScriptBundle("~/bundles/chosen").Include(
                        "~/Scripts/chosen.jquery.js",
                        "~/Scripts/chosen.proto.js"));

            bundles.Add(new ScriptBundle("~/bundles/datetimepicker").Include(
                        "~/Scripts/jquery.datetimepicker.full.min.js",
                        "~/Scripts/datepicker-pt-BR.js"));

            bundles.Add(new ScriptBundle("~/bundles/digitalClock").Include(
                        "~/Scripts/digitalClock.js"));

            bundles.Add(new ScriptBundle("~/bundles/msgBox").Include(
                        "~/Scripts/messagebox.min.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                        "~/Scripts/jquery-ui.min.js"));

            bundles.Add(new ScriptBundle("~/bundles/moment").Include(
                "~/Scripts/moment.min.js",
                "~/Scripts/moment-with-locales.min.js"));

            //ESTILOS CSS

            bundles.Add(new StyleBundle("~/styles/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));

            bundles.Add(new StyleBundle("~/styles/chosen").Include(
                      "~/Content/chosen.css"));

            bundles.Add(new StyleBundle("~/styles/datetimepicker").Include(
                      "~/Content/jquery.datetimepicker.min.css"));

            bundles.Add(new StyleBundle("~/styles/digitalClock").Include(
                      "~/Content/clock.css"));

            bundles.Add(new StyleBundle("~/styles/msgBox").Include(
                      "~/Content/messagebox.css"));

            bundles.Add(new StyleBundle("~/styles/jqueryui").Include(
                      "~/Content/jquery-ui/jquery-ui.min.css",
                      "~/Content/jquery-ui/jquery-ui.structure.min.css",
                      "~/Content/jquery-ui/jquery-ui.theme.min.css"));

        }

_Layout.cshtml

@using ControleHoras.APRESENTACAO.Models
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title</title>
    @Styles.Render("~/styles/css")
    @Scripts.Render("~/bundles/modernizr")
    @Styles.Render("~/styles/chosen")
    @Styles.Render("~/styles/datetimepicker")
    @Styles.Render("~/styles/digitalClock")

</head>
<body>
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <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" href="@Url.Action("Index", "Home")">
                    <img src="@Url.Content(System.Configuration.ConfigurationManager.AppSettings["logo"])" alt="" style="border: none; width: 150px; height: 50px;" />
                </a>

            </div>
            <div id="navbar" class="navbar-collapse collapse">
                @if (Session["usuario"] != null)
                {
                    <ul class="nav navbar-nav">

                            @{
                                if (Session["usuario"] != null)
                                {
                                    var usuario = (UsuarioViewModel)Session["usuario"];
                                    if (usuario.ClienteID.HasValue && usuario.ClienteID.Value > 0)
                                    {
                                        @*<li>@Html.ActionLink("Horas Extras", "HorasExtras", "Login")</li>*@
                                    }
                                    if (usuario.ProfissionalID.HasValue && usuario.ProfissionalID.Value > 0)
                                    {
                                        <li>@Html.ActionLink("Lançamentos", "Lancamento", "Login")</li>
                                        <li>@Html.ActionLink("Relatórios de Horas", "RelatorioHoras", "Relatorio")</li>
                                    }
                                    if (usuario.Adm)
                                    {
                                        <li class="dropdown">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Clientes<span class="caret"></span></a>
                                            <ul class="dropdown-menu">
                                                <li>@Html.ActionLink("Cadastro", "Search", "Cliente")</li>
                                                <li>@Html.ActionLink("Configurações de Rede", "Index", "ClienteIp")</li>
                                                <li>@Html.ActionLink("Loalização", "Index", "ClienteLocal")</li>
                                            </ul>
                                        </li>
                                        <li>@Html.ActionLink("Contratos", "Contrato", "Login")</li>
                                        <li class="dropdown">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Profissional<span class="caret"></span></a>
                                            <ul class="dropdown-menu">
                                                <li>@Html.ActionLink("Cadastro", "Search", "Profissional")</li>
                                                <li>@Html.ActionLink("Dispositivos Móveis", "Index", "ProfissionalDispositivo")</li>
                                            </ul>
                                        </li>
                                        <li>@Html.ActionLink("Lançamentos", "Lancamento", "Login")</li>
                                        <li>@Html.ActionLink("Usuários", "Usuario", "Login")</li>
                                        <li class="dropdown">
                                            <a class="dropdown-toggle" data-toggle="dropdown" href="#">Relatórios<span class="caret"></span></a>
                                            <ul class="dropdown-menu">
                                                <li>@Html.ActionLink("Relatórios de Horas", "RelatorioHoras", "Relatorio")</li>
                                                <li>@Html.ActionLink("Demonstrativo de Horas", "DemonstrativoHoras", "Relatorio")</li>
                                                <li>@Html.ActionLink("Relatório de Faturamento", "RelatorioFaturamento", "Relatorio")</li>
                                                <li>@Html.ActionLink("Acompanhamento Diário de Lançamentos", "AcompanhamentoDiario", "Relatorio")</li>
                                            </ul>
                                        </li>
                                    }
                                }
                            }
</ul>
                    <ul class="nav navbar-nav navbar-right">
                        <li class="active">@Html.ActionLink("Sair", "Logout", "Login")</li>
                    </ul>
                            }
            </div><!--/.nav-collapse -->
        </div>
    </nav>
    <div class="container body-content">
        @RenderBody()
    </div>

    <footer class="rodape">
        <p>&copy; @DateTime.Now.Year @System.Configuration.ConfigurationManager.AppSettings["empresa"] </p>
    </footer>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    <!--MessageBox-->
    @Scripts.Render("~/bundles/msgBox")
    @Styles.Render("~/styles/msgBox")
    <!--Jquery UI-->
    @Scripts.Render("~/bundles/jqueryui")
    @Styles.Render("~/styles/jqueryui")

    @RenderSection("scripts", required: false)
</body>
</html>
  • You need more details to help you. How are you deploying? Copying and pasting files? Something else, you can post the file BundleConfig?

  • As you said the site works in a local environment, make sure Section is pointing somewhere on your machine and not in the environment path. Error shows this path "E: Domains acensao.com.br public Views Shared_layout.cshtml" Check if the site can get to it.

  • @jbueno am generating the deploy files through Visual Studio’s PUBLISH

  • @Gabrielheguedusch I am not using physical path in the application. All style files and scripts are referenced in buddleconfig this way: Bundles.Add(new Stylebundle("~/Styles/css"). Include( "~/Content/bootstrap.css", "~/Content/site.css"));

  • @Otaviocamargo This is the real Bundle or just example?

  • @jbueno is the one in my code. And the content folder is published on the site.

  • go to shared_layout.cshtml and declare that line: @Section Styles { //links from your css or @Styles.Render(...) }

  • Post your file _Layout.cshtml and the login page file.

  • Please post your Bundleconfig too

  • I just changed all the style files to _Layout.html, and removed Rendersection("Styles"), to see if that was the problem. But it keeps giving error. It seems that it is not recognizing some files. Now gave error in the line @Styles.Render("~/Styles/digitalClock")

  • I just did one more test. I commented on all the script and css references. I now get the same error message in the Viewbag.Itlecall. Some configuration of the project must be wrong, because now it is not working or local

Show 6 more comments

1 answer

0

I believe your problem is related to @Url.Content that cannot be null.

In the section that picks up the logo has this call, try to remove this snippet to validate if this is the problem.

Page _Layout.cshtml:

 <a class="navbar-brand" href="@Url.Action("Index", "Home")">
                    <img src="@Url.Content(System.Configuration.ConfigurationManager.AppSettings["logo"])" alt="" style="border: none; width: 150px; height: 50px;" />
                </a>

Browser other questions tagged

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