ASP MVC JQuery Source Folder Location Web.config Key Value?

Posted on 2012-08-16
Last Modified: 2012-08-20
I'm new to MVC and have concerns about hard-coding the JQuery source folder paths in every controller using a JQuery script. I would not want to hunt every hard code path when changing from version 1.7.2 to 1.8.0. I have used this in a typical ASP .NET web.config to easily make changes to the .js source path. I know I could keep the same name in the scripts folder not matter what the actual .js version, but I would like to keep the real .js file name.

Q. Does MVC already have a way to centrally manage .js file name changes?

[Typical .aspx]
<scripttype="text/javascript"src="<%=ConfigurationSettings.AppSettings["jquery-js"] %>"></script>

             //code here ...

Question by:pointeman
    LVL 96

    Accepted Solution

    The approach that I use with my MVC 3 web site is to put the script links in the _Layout.cshtml (Razor engine).

    Since the _Layout view is the "master" view for each page, I have access to base Javascripts:

       <script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
        <script src="" type="text/javascript"></script>
        <script src="" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/")" type="text/javascript"></script>

    Open in new window

    If there is a view that needs a special .js file, then I put that <script> tag in that view.

        ViewBag.Title = "My Activity";
        Layout = "~/Views/Shared/_Layout.cshtml";
    <link href="@Url.Content("~/Content/mvccontrib.grid.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.mvccontrib.grid.js")" type="text/javascript"></script>

    Open in new window


    Author Closing Comment

    I downloaded the 'MVC Movies' tutorial app from and it had the same code as yours. Great minds think alike, Thx...

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now