Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2012-08-16
Medium Priority
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

Bob Learned earned 2000 total points
ID: 38304818
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="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.20/jquery-ui.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.tools.min.js")" 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

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

580 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