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 7497489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:07:15+00:00 2026-05-29T19:07:15+00:00

I am working on an ASP.NET MVC3 app. I was reading about good Javascript

  • 0

I am working on an ASP.NET MVC3 app. I was reading about good Javascript practices in various places and decided it would be best if I externalized the javascript and jQuery calls that were sitting in a <script/> tag at the bottom of my views.

I put each view’s Javascript in a separate file with a standardized naming convention so I could generate the <script/> tag to include the appropriate file in my layout view.

But it’s on the verge of being too complicated to be maintainable, and I have run into one problem that breaks the whole scheme, namely the need to occasionally insert URLs into the javascript.

For example: if I’m doing a $.getJSON call, I need to provide a URL. I’ve been generating them on the server side, in the views, using the UrlHelper class, like so:

var _RegistrationSelectClassUrl = '@Url.Action("SelectClass", "Student", new { area = "Registration", id = Model.Person.PersonID })';

And this worked nicely … up to the point where I externalized the javascript. No longer being part of views, calls to UrlHelper were just strings again.

So my question is this: if I stick with the externalized javascript, I need a way to insert or generate the appropriate URLs. Other than sticking a script section in the layout file that uses UrlHelper to define a constant for every URL I might want to use, I can’t think of a good one.

Any suggestions?

  • 1 1 Answer
  • 0 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-29T19:07:16+00:00Added an answer on May 29, 2026 at 7:07 pm

    External JS:

    var namespace = {
        init: function (url) {
            this._RegistrationSelectClassUrl  = url;
        },
        _RegistrationSelectClassUrl: ''
    };
    

    View:

    <script src="external/js.js" />
    <script>
        namespace.init('@Url.Action("SelectClass", "Student", new { area = "Registration", id = Model.Person.PersonID })');
    </script>  
    

    This is a basic example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently reading a book about ASP.NET MVC3 to learn working with this framework.
I am working on a web-app with ASP.NET MVC3. We are using nHibernate with
I'm working on an ASP.NET MVC app (using MVC3 RC2). Say I have 2
I am working on an ASP .NET Mvc 3 App and have installed Ninject.Mvc3
I am working on an asp mvc3 app that is using .NET 4 .
I'm working on a rather large Asp.net MVC3 project and would like to use
Working with ASP.NET MVC3, site is in beta and customer decided to rename one
After working with ASP.Net MVC, it has me thinking about Rails. I worked with
I am working with ASP.NET doing some client side javascript. I have the following
I've been working with asp.net MVC and am still not very good at it.

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.