Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 248241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:19:35+00:00 2026-05-11T21:19:35+00:00

I have been using ASP.NET MVC for six months or so and have been

  • 0

I have been using ASP.NET MVC for six months or so and have been checking out the Nerd Dinner example created by those Microsoft guys. One thing I noticed they did when enabling AJAX to RSVP for a dinner, is put the JavaScript references in the User Control being used for RSVPing.
(FILE: RSVPStatus.ascx)

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.Dinner>" %>

<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>    

This doesn’t seem right to me, as there is a really good chance I would be using these same libraries elsewhere, like logon authentication. Plus if I change script versions, I need to hunt down all the references to the libraries.

So I ask if my thinking is correct and these references should actually be in a more central location like the master page?

Please let me know what the best practice is for this and pro’s and cons if any.

  • 1 1 Answer
  • 5 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:19:36+00:00Added an answer on May 11, 2026 at 9:19 pm

    I would definitely advise against putting them inside partials for exactly the reason you mention. There is a high chance that one view could pull in two partials that both have references to the same js file. You’ve also got the performance hit of loading js before loading the rest of the html.

    I don’t know about best practice but I choose to include any common js files inside the masterpage and then define a separate ContentPlaceHolder for some additional js files that are specific to a particular or small number of views.

    Here’s an example master page – it’s pretty self explanatory.

    <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
    <head runat="server">
        ... BLAH ...
        <asp:ContentPlaceHolder ID="AdditionalHead" runat="server" />
        ... BLAH ...
        <%= Html.CSSBlock("/styles/site.css") %>
        <%= Html.CSSBlock("/styles/ie6.css", 6) %>
        <%= Html.CSSBlock("/styles/ie7.css", 7) %>
        <asp:ContentPlaceHolder ID="AdditionalCSS" runat="server" />
    </head>
    <body>
        ... BLAH ...
        <%= Html.JSBlock("/scripts/jquery-1.3.2.js", "/scripts/jquery-1.3.2.min.js") %>
        <%= Html.JSBlock("/scripts/global.js", "/scripts/global.min.js") %>
        <asp:ContentPlaceHolder ID="AdditionalJS" runat="server" />
    </body>
    

    Html.CSSBlock & Html.JSBlock are obviously my own extensions but again, they are self explanatory in what they do.

    Then in say a SignUp.aspx view I would have

    <asp:Content ID="signUpContent" ContentPlaceHolderID="AdditionalJS" runat="server">
        <%= Html.JSBlock("/scripts/pages/account.signup.js", "/scripts/pages/account.signup.min.js") %>
    </asp:Content>
    

    HTHs,
    Charles

    Ps. I would agree with Andrew in saying that any common JS that is defined directly inside the master page should be concatenated and minified.

    EDIT: My implementation of .JSBlock(a, b) as requested

    public static MvcHtmlString JSBlock(this HtmlHelper html, string fileName)
    {
        return html.JSBlock(fileName, string.Empty);
    }
    
    public static MvcHtmlString JSBlock(this HtmlHelper html, string fileName, string releaseFileName)
    {
        if (string.IsNullOrEmpty(fileName))
            throw new ArgumentNullException("fileName");
    
        string jsTag = string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>",
                                     html.MEDebugReleaseString(fileName, releaseFileName));
    
        return MvcHtmlString.Create(jsTag);
    }
    

    And then where the magic happens…

        public static MvcHtmlString MEDebugReleaseString(this HtmlHelper html, string debugString, string releaseString)
        {
            string toReturn = debugString;
    #if DEBUG
    #else
            if (!string.IsNullOrEmpty(releaseString))
                toReturn = releaseString;
    #endif
            return MvcHtmlString.Create(toReturn);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using ASP.NET MVC for the past few months, after successfully ignoring
For past projects(the last few have been web using asp.net mvc) we created a
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic
I have been using telerik extensions for an asp.net mvc project, more specifically the
I have been using http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application as guidance to help me create a repository.I have
Newbie question. I’m writing an ASP.Net MVC app in VB.Net and have been using
I have been learning to develop websites using ASP.NET MVC 2 for work... and
We have been using asp.net mvc for development. Sometimes, we need to put some
I am learning asp.net MVC, as I have been using the sqlconnection, sqlcommands etc
Using ASP.NET MVC 3, I have been struggling to set the selected value for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.