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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:04:30+00:00 2026-06-14T02:04:30+00:00

I am using ASP.NET MVC 4 to develop a web application. I have an

  • 0

I am using ASP.NET MVC 4 to develop a web application. I have an external javascript file which contains a method initializeLocation(). If I reference the file in the Index view of my Home controller it works fine. But when I try to reference the JS file in another view, and call the method in the body onLoad, then I get the following error:

Uncaught ReferenceError: initializeLocation is not defined

Here is the code of my view:

@{
    ViewBag.Title = "Online Users";
}

<html>
    <head>
        <title>Online Users</title>

    </head>

    <body onload="initializeLocation()">

        <h2>Online Users</h2>
        <div id="wrapper">
        <div id="upperPanel">
            <div>
                <ul id="onlineUsers" itemid="@HttpContext.Current.User.Identity.Name">

                </ul>
            </div>
            <div id="friends">

            </div>
        </div>
        <div id="bottomPanel">
            <input id="submitLocation" type="submit" value="Share Location" style="margin-left: 10px;" /><br />  
        </div>
    </div>​​​​​​​​​​​​​

        <label id="locLabel"></label>
        <div id="map" style="width: 100%; height: 600px"></div>
        <script>
            var Pusher_APP_KEY = 'b5ee1a1486b7f0cec06f';
        </script>
        <script src="http://js.pusher.com/1.12/pusher.min.js"></script>
        <script src="~/Scripts/jquery-1.8.2.js" type="text/javascript"></script>
        <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBsjVTOfgW39medqXn6cmOTfVyyxIX3Nl8&sensor=true"> </script>
        <script type="text/javascript">
            //postURL is used in locationFinder.js to set the URL of POST requests
            //It is declared here to be able to use a separate java file instead of embedding it
            var postURL = '@Url.Action("Index", "Home")';
        </script>
        <script type="text/javascript" src="~/Scripts/locationFinder.js"> 
        </script>
    </body>
</html>

And here is my controller code:

namespace LBSPrototype1.Controllers
{
    public class HomeController : Controller
    {
        private static readonly PusherProvider Provider = new PusherProvider
         (
             ConfigurationManager.AppSettings["pusher_app_id"],
             ConfigurationManager.AppSettings["pusher_key"],
             ConfigurationManager.AppSettings["pusher_secret"]
         );

        public ActionResult Index(string latitude, string longitude, string username)
        {
            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        //
        // GET: /Home/OnlineUsers
        [AllowAnonymous]
        public ActionResult OnlineUsers()
        {
            return View();
        }

        //
        // POST: /Home/OnlineUsers
        [AllowAnonymous]
        [HttpPost]
        public ActionResult OnlineUsers(string latitude, string longitude, string username)
        {
            var now = DateTime.UtcNow;
            var request = new ObjectPusherRequest(
                "chat_channel",
                "message_received",
                new
                {
                    lat = latitude,
                    lon = longitude,
                    user = username,
                    timestamp = now.ToShortDateString() + " " + now.ToShortTimeString()
                });
            Provider.Trigger(request);
            return View();
        }

    }
}

I’m new to MVC and am still getting used to the concept of controllers and such, but can’t see why the exact same code should work in one view and not the other.

  • 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-06-14T02:04:31+00:00Added an answer on June 14, 2026 at 2:04 am

    Instead of

    <script src="~/Scripts/jquery-1.8.2.js" type="text/javascript"></script>
    
    <script type="text/javascript" src="~/Scripts/locationFinder.js"></script>
    

    Use

    <script src="@Url.Content("~/Scripts/jquery-1.8.2.js")" type="text/javascript"></script>
    
    <script type="text/javascript" src="@Url.Content("~/Scripts/locationFinder.js")" ></script>
    

    The problem is the url which is render on the page. use @Url.Content to render a url with its rool path reference. it will render correct url while in routing.

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

Sidebar

Related Questions

I'm using ASP.NET MVC to develop a web application, deploying to IIS 7. I've
I am trying to develop a web application using ASP.net MVC 2. For that
I am using asp.net MVC to develop an application that will have ajax interactions.
I´m using internet explorer 8 and asp.net mvc 3 to develop my web application.
I am using ASP.NET MVC to develop a web application and would like to
I am using ASP.NET MVC to develop a site. The CSS file has grown
Hey guys! I'm using ASP.NET MVC to develop an application for a library with
Hai guys, As i want to develop an application using asp.net MVC, i dont
I am ASP.NET MVC to develop my application on web. This app requires a
I am developing an application which is web-based (asp.net MVC). The user configures reminders

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.