【问题标题】:mvc6 jquery referenced file not found未找到 mvc6 jquery 引用的文件
【发布时间】:2016-02-10 09:41:25
【问题描述】:

这有点让我头疼。

在 ASP5 MVC6 下我无法获取 JQuery 的来源。

我已经设置了 app.UseStaticFiles();它设置在 useMVC() 之前,如下所示

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseIISPlatformHandler();

        app.UseApplicationInsightsRequestTelemetry();
        HttpService.Configure(app.ApplicationServices.GetRequiredService<IHttpContextAccessor>());
        app.UseApplicationInsightsExceptionTelemetry();
        app.UseSession();         
        app.UseStaticFiles(new StaticFileOptions
        {
            ServeUnknownFileTypes = true,
        });

        app.UseMvc();
    }

我的布局文件似乎可以提供 .css 文件,但不能提供脚本。我什至可以通过浏览器导航/查看它在浏览器中加载文本的相关 js 文件。

Visual Studio 总是有相同的信息(即使路径是正确的)

07:27:35.4149:未找到引用文件“~/lib/jquery/dist/jquery.min.js”。 07:27:35.4149: 未找到引用文件“~/lib/bootstrap/dist/js/bootstrap.min.js”。

在我的布局中:

<body>
@await Component.InvokeAsync("Navigation")
@RenderBody()
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.min.js"></script>
@RenderSection("scripts", required: false)

【问题讨论】:

  • 也许您尝试通过文件系统路径访问它?您需要通过网络服务器路径访问脚本。
  • 我尝试使用 Url.Content() 但同样的问题
  • 不不,只是简单的想:在里面写http://localhost/yourproject之类的东西。或者只是基本 url 下文件的路径。 PS:当您运行您的应用程序时,请获取浏览器地址并尝试找出基本路径。这就是你所需要的。

标签: javascript c# jquery visual-studio-2015 asp.net-core-mvc


【解决方案1】:

令人尴尬的是,我只是在我的一个页面上错过了@section scripts { },并且因为调试器一直说它无法在文件路径中找到 .js 的事实而分心。

我不知道为什么 vs2015 调试器总是说它无法引用该文件,但它现在启动时确实可以正常工作..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 2020-03-28
    相关资源
    最近更新 更多