Skip to content

HTMLHelper Extensions Bundling

Angelo edited this page Apr 11, 2018 · 4 revisions

Getting started with the Bundling Extensions

The purpose of the Bundling Controller Extensions is to allow for an individual to add per page script bundle and style bundle references from the controller to the head of the view.
To get started follow these steps:

  1. To get started you will need to add this using statement in your controller if you have not already done so.
    using UAngelASPExtentions.ASPMVCControllerExtentions
  2. You will also need to add required code to the view.
    This will require a few steps if you have not already done so while working with another extension category. If you have followed these steps already in another section please ignore them.
      1. Find the "~\Views\webconfig" file
      2. In the file find the <namespaces>; under <pages pageBaseType="System.Web.Mvc.WebViewPage">; under <system.web.webPages.razor>; under the root.
      3. Add the line <add namespace="AngelASPExtentions.ASPMVCRazorHTMLHelperExtentions" />
    1. Add the following Code to the html head of the view @Html.RenderBundles(). Note: This may be located in a layout view.

!Note!: ViewBag.ScriptBundles should be kept empty as the method makes use of this property name space in the view bag. If it is not empty It may throw an exception.

Using the Bundling Extensions

Usage Is simple after adding @Html.RenderBundles() to the views head.
Script Bundles
To add a script simply follow these steps:
  1. Make a script bundle. If you need help with this visit Bundling and Magnification Documents as the bundling system its self is a MS product.
  2. Then you will need to the following code to your controller where appropriate. @Html.AddToRenderscriptBundles("~YourBundle") and it will return a the HTMLHelper so that you can chain call.

Over Loads include


         ///  
         ///     For Use on view side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention 
         ///     this one in particular is used For style bundles 
         ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all 
         /// throws exeption on  
         ///   ViewBag.StyleBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles 
         /// Returns  
         ///     the Conroller for easy Chaining that is line seperatatable for easy read 
         ///  
         /// The HtmlHelper to chain off(us this. in method) 
         /// A list of virtual paths on which to find StyleBundles 
         /// HtmlHelper for chaining 
         public static HtmlHelper AddToRenderStyleBundles(this HtmlHelper This, string[] StyleBundles) 

 
         ///  
         ///     For Use on view side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention 
         ///     this one in particular is used For style bundles 
         ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all 
         /// throws exeption on  
         ///   ViewBag.StyleBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles 
         /// Returns  
         ///     the Conroller for easy Chaining that is line seperatatable for easy read 
         ///  
         /// The HtmlHelper to chain off(us this. in method) 
         /// A list of virtual paths on which to find StyleBundles 
         /// HtmlHelper for chaining 
         public static HtmlHelper AddToRenderStyleBundles(this HtmlHelper This, List StyleBundles) 

 
         ///  
         ///     For Use on view side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention 
         ///     this one in particular is used For style bundles 
         ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all 
         /// throws exeption on  
         ///   ViewBag.StyleBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles 
         /// Returns  
         ///     the Conroller for easy Chaining that is line seperatatable for easy read 
         /// Note 
         ///     Does nothing if input is null useful for place holding or templating  
         ///     This also means it ill not throw unless it has input 
         ///  
         /// The HtmlHelper to chain off(us this. in method) 
         /// A list of virtual paths on which to find StyleBundles 
         /// HtmlHelper for chaining 
         public static HtmlHelper AddToRenderStyleBundles(this HtmlHelper This, string StyleBundles) 

 
         ///  
         ///     For Use on view side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention 
         ///     this one in particular is used For script bundles 
         ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all 
         /// throws exeption on  
         ///   ViewBag.ScriptBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles 
         /// Returns  
         ///     the Conroller for easy Chaining that is line seperatatable for easy read 
         ///  
         /// The HtmlHelper to chain off(us this. in method) 
         /// A list of virtual paths on which to find ScriptBundles 
         /// HtmlHelper for chaining 
         public static HtmlHelper AddToRenderScriptBundles(this HtmlHelper This, string[] ScriptBundles) 

 
         ///  
         ///     For Use on view side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention 
         ///     this one in particular is used For script bundles 
         ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all 
         /// throws exeption on  
         ///   ViewBag.ScriptBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles 
         /// Returns  
         ///     the Conroller for easy Chaining that is line seperatatable for easy read 
         ///  
         /// The HtmlHelper to chain off(us this. in method) 
         /// A list of virtual paths on which to find ScriptBundles 
         /// HtmlHelper for chaining 
         public static HtmlHelper AddToRenderScriptBundles(this HtmlHelper This, List ScriptBundles) 

         ///  
         ///     For Use on views side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention 
         ///     this one in particular is used For script bundles 
        ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all 
         /// throws exeption on  
         ///   ViewBag.ScriptBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles 
         /// Returns  
         ///     the HtmlHelper for easy Chaining that is line seperatatable for easy read 
         ///  
         /// The HtmlHelper to chain off(us this. in method) 
         /// A list of virtual paths on which to find ScriptBundles 
         /// HtmlHelper for chaining 
         public static HtmlHelper AddToRenderScriptBundles(this HtmlHelper This, string ScriptBundles = null) 
Style Bundles
To add a style simply follow these steps:
  1. Make a style bundle. If you need help with this visit Bundling and Magnification Documents as the bundling system its self is a MS product.
  2. Then you will need to the following code to your controller where appropriate. @Html.AddToRenderStyleBundles("~YourBundle") and it will return a the contoller so that you can chain call.

Over Loads include


        ///     You should consider HtmlHelper.AddToRenderStyleBundles extention first as this is bad practice but might be useful
        ///     For Use on controllers side to create a list for Rendering in view using HtmlHelper.RenderBundlesSylesAndScripts extention
        ///     this one in particular is used For style bundles
        ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all
        /// throws exeption on 
        ///    ViewBag.StyleBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles
        /// Returns 
        ///     the Controller for easy Chaining that is line seperatatable for easy read
        public static Controller AddToRenderStyleBundles(this Controller This, string[] StyleBundles)

        ///     You should consider HtmlHelper.AddToRenderStyleBundles extention first as this is bad practice but might be useful
        ///     For Use on controllers side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention
        ///     this one in particular is used For style bundles
        ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all
        /// throws exeption on 
        ///   ViewBag.StyleBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles
        /// Returns 
        ///     the Controller for easy Chaining that is line seperatatable for easy read
        public static Controller AddToRenderStyleBundles(this Controller This, List StyleBundles)

        ///     You should consider HtmlHelper.AddToRenderStyleBundles extention first as this is bad practice but might be useful
        ///     For Use on controllers side to create a list for Rendering in view using Html.VRenderBundlesSylesAndScripts extention
        ///     this one in particular is used For style bundles
        ///     Is useful for perpage bundles so it can be rendered in the head while not Requiring it for all
        /// throws exeption on 
        ///   ViewBag.StyleBundles not being NULL and is not a Array as presset by earlier call, because it adds your list to ViewBag.StyleBundles
        /// Returns 
        ///     the Controller for easy Chaining that is line seperatatable for easy read
        /// Note
        ///     Does nothing if input is null useful for place holding or templating 
        ///     This also means it ill not throw unless it has input
        public static Controller AddToRenderStyleBundles(this Controller This, string StyleBundles)