Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • MVC styling and Scripting

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 348
    Comment on it

    In the design page if you want to add libraries for script files and CSS files so for doing that in MVC architecture you need to use two tags :

    1 Styles.Render

    2 Scripts.Render

     

    Style.Render is used to add bundle of CSS files. Styles.Render create style tag for the CSS.

    Scripts.Render is also used to add all Script files by searching script tag for the Script .

     

    Here is the example:

     

      /*  This is the repository for all the script files  */

     

      public class BundleConfig
        {
         public static void RegisterBundles(BundleCollection bundles)
         {
         bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
         "~/Scripts/jquery.unobtrusive*",
         "~/Scripts/jquery.validate*"));
    
    
         /*  This will include the reference of all the library files into your application */ 
    
    
         bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
         "~/Content/themes/base/jquery.ui.core.css",
         "~/Content/themes/base/jquery.ui.resizable.css",
         "~/Content/themes/base/jquery.ui.selectable.css",
         "~/Content/themes/base/jquery.ui.theme.css"));
         }
        } 
    

     

     

    So we have the class which contain all the collection of the script files to include these references into your project

     


     

    @*@section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
    }*@

     

    You need to add it into your view if you want to apply it on single view.

     

     

    If you want to make it global for all view add it in the Layout.cshtml which is in View shared folder.


     

        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: