-2

Ola, criei uma aplicação a pouco tempo e obtive o jquery via Nuget, porém ele fica dando erro ao inicializar o jquery. Eu tenho a seguinte função em um arquivo js.

$("#myNav").bind("mousewheel", function (ev, delta) {
    var scrollTop = $(this).scrollTop();
    $(this).scrollTop(scrollTop - Math.round(delta));
}); 

E o meu Layout tem o seguinte HTML

<!DOCTYPE html>
<html>
<head>
    <script src="~/Scripts/View/Layout.js" type="text/javascript"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DK Design - @ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</head>
<body>
    <div>
        <div class="navbar navbar-light bg-light">
            <table style="width:100%">
                <tbody>
                    <tr>
                        <td align="right" valign="top" width="1%">
                            <button type="button" class="navbar-toggler" onclick="ControlNav()">
                                <span class="navbar-toggler-icon"></span>
                            </button>
                        </td>

                        <td align="center" width="90%">
                            <h1 class="logoFont">DK DESIGN</h1>
                        </td>

                        <td align="left" width="9%">
                            <span>Login </span><span> | </span><span> Registro</span>
                        </td>
                    </tr>
                </tbody>
            </table>

            <div id="myNav" class="overlay">
                <!-- Overlay content -->
                <div class="overlay-content">
                    @Html.ActionLink("Home", "Index", new { controller = "Home" }, new { @class = "font-custom-color" })
                    @Html.ActionLink("Contet Test", "Index", new { controller = "ContentTest" }, new { @class = "font-custom-color" })
                    <a href="#">Clients</a>
                    <a href="#">Contact</a>
                </div>

            </div>
        </div>
    </div>
    <div>
        @RenderBody()
    </div>

    <hr />
</body>
</html>

E o Bundle esta assim:

using System.Web;
using System.Web.Optimization;

namespace DKDSGN
{
    public class BundleConfig
    {
        // Para obter mais informações sobre o agrupamento, visite https://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

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

            // Use a versão em desenvolvimento do Modernizr para desenvolver e aprender. Em seguida, quando estiver
            // pronto para a produção, utilize a ferramenta de build em https://modernizr.com para escolher somente os testes que precisa.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

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

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

Ja tentei inicializar o jquery antes da função, mas ele não vai .. tentei referenciar os arquivos por src tbm mas não rolou, será que alguem poderia me ajudar ?

5
  • Vc pode ver tudo que está acontecendo na página (inclusive o código-fonte) usando o Dev Tools (F12).
    – Sam
    30/12/2018 às 23:57
  • No navegador ? Ele mostra esse erro no console .. E indica que o erro e no inicio da função, mas mesmo uma simples de document.read ele da esse mesmo erro. 31/12/2018 às 0:00
  • Bom, o que sei é que o erro citado é resultado do não carregamento do jQuery.
    – Sam
    31/12/2018 às 0:03
  • Sim eu reparei nisso, é justamente isso que to perguntando, ja tentei inicializar por bundle, ja tnetei inicializar por src , ele não esta referenciando no projeto de maneira alguma 31/12/2018 às 0:09
  • Então me parece que o problema é no asp.net. Aí eu já não entendo. Boa sorte aÍ! :)
    – Sam
    31/12/2018 às 0:10

1 Resposta 1

0

Coloca isso no final da View nesta ordem:

--omitido
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
    <script src="~/Scripts/View/Layout.js" type="text/javascript"></script>
</body>
</html>

Confira no developer tools do chrome se os arquivos foram carregados:

inserir a descrição da imagem aqui

Se possível mande um print dos diretórios da sua solution.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .