Troubleshooting ASP.NET MVC5: Partial view not loading dynamic JavaScript reference

In an effort to update a partial View containing an interactive world map, my objective is to refresh it with new data. I have a Controller action

public JavaScriptResult DynMap(int id, List<int> relevantCountries = null){}

This action returns the map data as JavaScriptResult.

I am calling this Javascript in my Partial View "MapSite" using

<script src="/JS/DynMap/@ViewBag.GameRoomID"></script>

The Partial View "MapSite"

public ActionResult MapSite(int id)
{
   ViewBag.GameRoomID = id;
   return PartialView("MapSite");
}

This view is then displayed in my main page like this:

<td id="map">
    @{Html.RenderAction("MapSite", "JS");}
</td>

Everything works perfectly fine! However, when I attempt to reload the MapSite at runtime with new values using: $('#map').load('/JS/MapSite/4') (4 is static for testing purposes), the Partial View does not contain the DynMap Javascript.

Is this a bug? Is it not possible to load external Javascript in this way dynamically? Although the breakpoint inside the Controller DynMap method is hit, the map appears empty because the DynMap values are missing.

Answer №1

Resolution

After thorough investigation, I have confirmed that my method is functioning as expected! In my unique scenario, the issue arose because the JavaScript content was loaded after the HTML page itself. As a result, the window.onload() function within the JavaScript did not trigger automatically, necessitating manual intervention.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Bootstrap Modal to trigger an Action Result function when a button is clicked

I could use some assistance. In my current setup, I have a file picker that loads a file into a specific table in my database. When the user clicks a button, a bootstrap modal pops up to ask if they are uploading more files. This is how it looks in my vi ...

Using a single component more than once within react-router configuration

Within my React application, I have a class named MainContainer that is responsible for displaying content. This MainContainer class has a child component called SidebarContainer which lists various links. By default, when rendering the main container, the ...

The div layer is positioned above the flash object

I have successfully implemented a method where I position a div over a webpage containing a flash object. This absolutely positioned div has a high z-index and captures click events. The main goal is to trigger the click event on the div when the flash obj ...

execute a rigorous compilation during the ng build angular process

I am currently working on a project using angular-cli and I have configured my package.json with the following scripts: "scripts": { "ng": "ng", "build": "ng build --base-href /test/", "prod": "ng build --prod --base-href /test/" } According to the ...

Design a div element with a responsive aspect ratio of 16:9

Hey everyone, I've been working on creating a responsive div with a 16:9 ratio. However, I've noticed that when I resize the window, the container3 remains the same size. Can anyone spot an issue in my code and offer some help? Thanks! $(docum ...

Initiating an Ajax POST request when the onblur() event is triggered

Having an issue with Ajax. I'm trying to submit a changed value from an input field on the onblur() event, but there's a flicker that's bothering me. When I enter a new value and click away, the old value briefly flashes back before changi ...

What is the proper way to send an AJAX request with the data type set to

I am currently working on creating my own POST request. Below is the function I have written: function sendPost(o) { var h = new XMLHttpRequest(); h.onreadystatechange = requestComplete; function requestComplete() { if (h.readyState = ...

JavaScript - Unable to run 'getImageData' method on 'CanvasRenderingContext2D': Provided value is not a 'long' type

My setup involves a video element and a canvas element as seen below: <video id="video" width="640" height="480"></video> <canvas id="canvas" width="640" height="480"></canvas> The goal is to decode a PDF417 barcode from the webca ...

Create a recursive array structure that contains two distinct data types and specific guidelines

I have a unique array structure where the odd index always contains elements of TypeA and the even index always contains elements of TypeB. It is guaranteed that this array will always have an even length, never odd. The data structure of this array must ...

Node.js readline: SyntaxError: Unexpected token =>

Currently, I am diving into node.js and have found myself in need of utilizing the readline module for a new project. Below is the code snippet that I extracted directly from the official readline module example. const readline = require('readline&ap ...

How to selectively disable buttons in a group using React

I am working with an array of data const projectTypeValues = [ { name: 'Hour', value: 'hour'}, { name: 'Day', value: 'day'}, { name: 'Session', value: 'session'}, { name: 'project', valu ...

I'm puzzled as to why a div tag suddenly becomes invisible when I attempt to link it with a v-for directive in my code

I am facing an issue with the div tag assigned to the log class. My objective is to populate the text using data retrieved from the API response. However, when I attempt to include the v-for directive, the entire div mysteriously disappears from the brow ...

Switching the visibility of rows in a table

Imagine this as my example table: <table> <tr> <td>a</td> <td>one</td> <td>two</td> </tr> <tr> <td>b</td> <td>three</td> <td>four</t ...

Retrieve a specific div element from the response data in AngularJS

Struggling to extract a specific div element from an AJAX response in Angular? Don't want the entire page content to be displayed? Tried various methods but nothing seems to work. Here's what I have attempted: $http({ method: 'GET&a ...

Issue with Javascript/Jquery functionality within a PHP script

I have been attempting to incorporate a multi-select feature (view at http://jsfiddle.net/eUDRV/318/) into my PHP webpage. While I am able to display the table as desired, pressing the buttons to move elements from one side to another does not trigger any ...

STLLoader enhances CSG operation functionality

I'm attempting to use a boolean operation on a loaded STL mesh file with ThreeCSG.js. Here is the code snippet: function openFile() { filePath = document.form.selectedFile.value; var loader = new THREE.STLLoader(); loader.addEventListener ...

Selenium's WebDriver getAttribute function can return an object of type "object",

In my selenium script, I aim to extract text from table columns following the cell with the specified value. Although the script functions, I encounter an issue where getText() returns [Object Object] in my node.js console. I have attempted various method ...

Unlocking Google APIs Data through Service Account in JavaScript without User Approval

Is there a way to obtain an Access Token for Google APIs without requiring user consent, utilizing a Service Account in JavaScript? Alternatively, is it possible to retrieve the Access Token using an API Key, Client ID, and Client Secret? ...

Issue with AJAX request on Internet Explorer versions 8 and 9

This script is functioning properly in Internet Explorer 10 and above, as well as Chrome and other browsers. However, it encounters issues specifically with IE8 and IE9. <table id="table" border="1"> <tbody style="display: table-row-group"&g ...

The program detected an unfamiliar command named 'node_modules', which is not recognized as an internal or external command, operable program, or batch file

I have integrated gulp into my project. Successfully installed gulp Added the npm script Executed the script using "npm start" Encountered the following error:- **> start node_modules/.bin/gulp watch 'node_modules' is not recognized as an ...