BundleConfig.cs不生成脚本引用

时间:2023-01-13 12:07:57

I've been trying to get MVC 5 remote validation working in my little project. I've been reading enough about bundling in order to get the basics of it. I created a bundle for my jqueryval bundle, like so:

我一直在努力让MVC 5远程验证在我的小项目中运行。我一直在阅读有关捆绑的内容,以获得它的基础知识。我为我的jqueryval包创建了一个包,如下所示:

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

However, when I publish the page, view source, the only scripts that are rendered, are as follows:

但是,当我发布页面时,查看源,唯一呈现的脚本如下:

    <script src="/myApp/Scripts/jquery-2.1.0.js"></script>
    <script src="/myApp/Scripts/jquery.validate.js"></script>

notice that the query.validate.unobstrusive.js is missing. Now I know this is the key component in getting my validation working, because when I manually add the query.validate.unobstrusive.js to my view page like so:

请注意,缺少query.validate.unobstrusive.js。现在我知道这是使我的验证工作的关键组件,因为当我手动将query.validate.unobstrusive.js添加到我的视图页面时,如下所示:

  @section Scripts {
  @Scripts.Render("~/bundles/jquery")
  @Scripts.Render("~/bundles/jqueryval")
  <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript" />
  }

everything just works.

一切正常。

So now I'm left wondering, is there something I'm doing wrong with the Bundling? Why would this script not show up?

所以现在我想知道,有什么我在捆绑时做错了吗?为什么这个剧本不会出现?

1 个解决方案

#1


0  

Do you have it enabled in your web.config?

你在web.config中启用了吗?

<appSettings>
   <add key="ClientValidationEnabled" value="true" />
   <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

You won't need to include it in the BundleConfig.cs. Just make sure you havejquery.validate.unobstrusive.jsandjquery.validate.unobstrusive.min.jsin yourscriptsfolder

您不需要将它包含在BundleConfig.cs中。只要确保你有jquery.validate.unobstrusive.jsandjquery.validate.unobstrusive.min.jsin yourscriptsfolder

#1


0  

Do you have it enabled in your web.config?

你在web.config中启用了吗?

<appSettings>
   <add key="ClientValidationEnabled" value="true" />
   <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

You won't need to include it in the BundleConfig.cs. Just make sure you havejquery.validate.unobstrusive.jsandjquery.validate.unobstrusive.min.jsin yourscriptsfolder

您不需要将它包含在BundleConfig.cs中。只要确保你有jquery.validate.unobstrusive.jsandjquery.validate.unobstrusive.min.jsin yourscriptsfolder