R.D Ip

R.D Ip

  • NA
  • 76
  • 7.6k

issue with bundleconfig file

May 7 2021 4:38 AM
I add a jquery path in bundle config.cs but give an below error
 
Create:52 Uncaught ReferenceError: $ is not defined
at Create:52
 
BundleConfig.cs
  1. public class BundleConfig  
  2. public static void RegisterBundles(BundleCollection bundles)    
  3. {    
  4.          
  5.     //here i add a jquery path    
  6.     bundles.Add(new ScriptBundle("~/Scripts").Include(    
  7.               "~/Scripts/jquery-3.4.1.min.js",    
  8.               "~/Scripts/jquery.validate.min"    
  9.         ));   
when I create a new project in mvc
 
then Bydefault jquery add in project see below
 
 
 
Create.cshtml
  1. <h2>Create</h2>    
  2. <div>    
  3.     <div>    
  4.           Name : @Html.EditorFor(x => x.name)    
  5.     </div>    
  6. </div>    
  7. @*<script src="~/Scripts/jquery-3.4.1.min.js"></script>*@     
  8. <script type="text/javascript">    
  9.     $(document).ready(function () {    
  10.         //debugger  
if i uncomment this below code
 
Create.cshtml
  1. <script src="~/Scripts/jquery-3.4.1.min.js"></script>    
and comment the below code
 
BundleConfig.cs
  1. ////here i add a jquery path    
  2. //bundles.Add(new ScriptBundle("~/Scripts").Include(    
  3. //          "~/Scripts/jquery-3.4.1.min.js",    
  4. //          "~/Scripts/jquery.validate.min"    
  5. //    ));  
then working fine
 
but I am trying to add jquery in bundle file then give an error
 
why I am using bundle.config file because when project run then load the jquery library only at once
 
that is the reason I am adding bundle.config inside jquery path
 
If I use script add individually in view page then request load time increase
  1. <script src="~/Scripts/jquery-3.4.1.min.js"></script>   
that is reason I am using bundle.config file

Answers (1)