Tips for troubleshooting JavaScript within a cshtml file

I found a .cshtml file with the following structure (please excuse any inaccuracies in my JavaScript jargon)

@model SomeViewModel
@{ Response.ContentType = "application/x-javascript"; }

$(function() {
         // Code for handling Javascript events here
    }
});

$(function ($) {
        // Extensions for JQuery.DatePicker in Javascript go here
    }
});

I suspect there is a bug that needs to be fixed in the second JS block, but I'm having trouble debugging it. I am using Chrome.

The situation is complicated by the presence of a MyDatepicker.js file elsewhere in the solution with the same javascript code, and a MyDatepicker.min.js which appears at runtime and can be debugged (to some extent).

Therefore:

  • What happens to the JS code in the cshtml file - can I disregard it?
  • How can I ensure that a non-minified version of the javascript is loaded?
  • How do I determine where the minified version of the script originates from?

Following the advice provided below, I discovered the following class.

public class MyDatePickerController : Controller
{
    // GET: /jquery.mydatepicker.js
    [Minify]
    [HttpGet]
    public ActionResult Index()
    {
        MyDatePickerViewModel model = new MyDatePickerViewModel(); 

        return View(model);
    }
}

This seems to clarify how the javascript gets minified.

Since there is a MyDatePicker.js file alongside the code in the .cshtml file, I am still uncertain about which version of the javascript is being loaded. I will edit one of them, remove the minify, and observe which one is loaded.


Now that I have identified why the script was getting minified, I have confirmed that the executed javascript was from the razor file (.cshtml)

Answer №1

Ensure to review your bundleconfig file, as it may have combined MyDatepicker.min.js with additional js files.

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

Obtain the accurate sequence of tr elements in the form of a jQuery object

Even though you can define tfoot before tbody in the source code, when displayed in the browser tfoot will still appear last: <table> <thead><tr><th>i get displayed first</th></tr></thead> <tfoot><t ...

What is the best way to present JSON data retrieved from an API on different pages using Next.js?

I am currently working on two pages that are connected: one is an API page called secured.js (where user session data is processed) and the other is a normal page also named secured.js (which displays the processed content from the API page). This is the ...

Favicon in browser blinks when hash changes

Whenever I adjust the hash location using either document.location.hash or window.location.hash, there seems to be a slight 'blinking' effect in most browsers. It's quite unattractive and I need to find a way to prevent it, especially since ...

Restrict Text Input Field to Accept Only Specific Domain

Hey there! I've set up a text input box for users to link their Tripadvisor page to their profile. I want to make sure that when they paste the URL in, it is checked for the correct format. For example, if someone pastes: or , then allow the link. Ho ...

Is it possible for me to save external CDN JavaScript files to my local system?

Normally, I would include scripts from other providers in my application like this: <script src="https://apis.google.com/js/api.js"></script> However, I am considering whether it is feasible to simply open the URL , and then copy and paste th ...

Utilize ES6 in React to dynamically update state with setState and retrieve state with the

Recently I discovered a technique for handling multiple input events using dynamic state. If I have a state setup like this this.state = { name_1: 'john', name_2: 'james' } I can access my state values like this [1,2].forEach ...

Threejs collada loader tutorial: converting a scene into an object3d

Currently working on an augmented reality project and I'd like to incorporate an Object3D into another object for rendering purposes. Using the ColladaLoader to bring in the object, but the output is a Scene which doesn't quite fit my requiremen ...

How can I redirect applications from a web browser to Safari?

Is there a way to redirect applications from a browser to Safari? For Android devices, I have implemented a feature where if a user opens my site through a browser built-in within apps like Facebook or Telegram, they are automatically redirected to Google ...

What is the best way to distinguish between the paths for administrators and regular users?

Currently, I am in the process of setting up routes using node js for a dashboard. Firstly, users will need to log in to obtain a JWT token. With the Token, users can access various user-related routes such as editing, deleting, and logging out. However, ...

Issues with dependencies in npx create react app

After initiating a new react project with npx create-react-app client, I have encountered an issue where the react-scripts command is not found, preventing me from running the start script. Is there a way to resolve this problem? Furthermore, when attempt ...

I'm attempting to store this HTML code in local storage in order to utilize it on a new cart page, but I keep encountering an error

Here is the HTML snippet: <div class="cofefe"> <img src="photos/Shop%20-%20French%2Roast.png"> <p>Somecoffee</p> <p>15</p> <p>French ...

What is the purpose of being able to include additional scripts within package.json files?

I am attempting to include a new script in the package.json file under the scripts section. For instance, I have the following: { "scripts": { "delete": "rm -f wwwroot/*.js wwwroot/*.css wwwroot/*.html wwwroot/*.map" "watch": "npm run delete; parc ...

When working with MSAL version 0.1.3 in angularJS, it appears that there is an issue as the Msal.IdToken

Currently, I am utilizing this approach to decode the token and retrieve its expiration date. Here is the code snippet: var decode = Msal.IdToken(localStorage["msal.idtoken"]); This method is chosen to prevent the need for adding an additional jwtdecode ...

Invoke a function from a popup window, then proceed to close the popup window and refresh the parent page

When a link in the parent window is clicked, it opens a child window. Now, when the save button is clicked in the child window, I need to trigger a Struts action, close the child window, and reload the parent window. function closeChildWindow(){ document. ...

The counterpart of the RxJS setTimeout operator

Looking for a RxJS operator alternative to set/clearTimeout in these circumstances: this.mouseEnterSubscription = this.mouseEnterStream .subscribe(() => { this.timeout = setTimeout(() => { void this.playVideo(); }, 500) }); this.mo ...

Ways to update list item text with jQuery

I am attempting to create a button that can replace the content of a list item. Although I have looked at other solutions, I keep encountering this error message: Uncaught TypeError: Object li#element2 has no method 'replaceWith' I have experime ...

Is there a potential race condition in React when switching between lists?

I'm currently working on setting up a queue system where users can move items between different lists, such as from "available" to "with client". The queue's state is managed in the root React component like this: this.state = { queue: { a ...

req.next does not exist as a function [END]

I am currently working on developing a website and I have encountered an issue in the dashboard stage. The error message TypeError: req.next is not a function keeps appearing, particularly when trying to create a subpage for the dashboard. I am utilizing t ...

JavaScript dialog on top of a flash video

I have a unique system in place: Upon opening the main site, a flash image gallery appears. When a user clicks on an image, I utilize Flash's "ExternalInterface.call" function to invoke a JavaScript function that opens a Java dialog modal called NyroM ...

Persistently Undefined Angular Attribute

I have been trying to dynamically bind a CSS class using an AngularJS function. While the functionality is working properly, I keep encountering numerous errors in the browser console. Can anyone offer assistance with this issue? I have included my code an ...