2

I am trying to create a Datetime picker for birthdays, as you can see here, the solution requires the use of many links and script sources.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/es.js"></script>
<br>
<div class="form-group">
 <div class='input-group date datepicker' name="datepicker" >
      <input type='text' class="form-control placementT" id="fecha">
         <span class="input-group-addon">
               <span class="glyphicon glyphicon-calendar">
               </span>
        </span>
  </div>

I want to use mvc bundles, with links to those scripts and stylesheets. But the solution I found: How to setup bundles using CDN in ASP.NET MVC? does not explain how to include many links in a bundle. Instead, uses one link per bundle:

bundles.Add(new ScriptBundle("~/bundles/jquery", "http://code.jquery.com/jquery-2.0.3.min.js")
   .Include("~/Scripts/jquery-{version}.js"));

bundles.Add(new StyleBundle("~/bundles/bootstrap", "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css")
            .Include("~/Content/bootstrap.css"));

As you can see, I would have to 6 different bundles.Add. I want to be able to do something like this:

bundles.Add(....,"https://maxcdn","https link","another link")

How can I do it ? I want to include that bundle in my view like this:

@Scripts.Render("~/bundles/myCustomBundle")
Adi Ep
  • 509
  • 1
  • 5
  • 22
ev vk
  • 345
  • 1
  • 4
  • 18

1 Answers1

1

This an example you can change parameters according to your need.

Example

The cdnHost parameter refers to alternate URL for the bundle when it is stored in a content delivery network. The cdn bundle is supposed to be loaded as one file and should contain a combined content of all files uploaded on cdn for example server path is https://ajax.googleapis.com/ in your case then you can load multiple script file as one bundle you just need to provide relative path of other files in include method.

var cdnHost = "https://ajax.googleapis.com/";
    bundles.Add(new ScriptBundle("~/bundles/angularCDN", cdnHost).Include(
                            "~/ajax/libs/angularjs/1.3.0-beta.17/angular.js",
                            "~/ajax/libs/angularjs/1.3.0-beta.17/angular-cookies.js",
                            "~/ajax/libs/angularjs/1.3.0-beta.17/angular-route.js"));

i hope it'll work for you.

Muhammad Asad
  • 1,772
  • 16
  • 23