JW1121
JW1121

Reputation: 3

Visual Studio won't update ASP.Net MVC project when making changes in JS file

Visual studio won't update the project when I change something in a javascript file that is the source of an html file. This happens almost all the time.Very rarely does it update right away when I make changes, rebuild, and debug.

I have a cshtml file in my View folder that has a

<button id="SaveButton" onclick="SaveNExit()" type="button">Save & Exit </button>

along with <script src="~/js/Index.js"></script> in the cshtml page.

I have the Index.js file with the function it it

function SaveNExit() {
        document.getElementById("SaveButton").disabled = true;
}

--This works when I click it, it fades out or is disabled. Then I do this (add an alert message):

function SaveNExit() {
        document.getElementById("SaveButton").disabled = true;
        alert("Your form was saved");
}

-- I rebuild the solution and debug. I click the button. The button fades-out/disables just like before, but the alert message doesn't pop up.

I tried cleaning and rebuilding solution, I tried restarting Visual Studio, and I tried restarting my computer. Nothing works. It works after over night where I turn off my computer for about 9 hours and turn it back on the next day. Any idea why?

Upvotes: 0

Views: 1510

Answers (2)

Roman.Pavelko
Roman.Pavelko

Reputation: 1665

  1. Changing content of js/cshtml file does not affect project file. Project file only has references to these files, so in order to have a change in project file, you need to add/delete file within the project (not content update of existing one).
  2. Your actual problem is related to browser caching. After you update your js/css file and go to browser to check the difference, browser uses previous cached version and that is why you don't see your alert message. Press CTRL+F5 in browser and click your button again, it should update all cached files in browser and do the trick.

Upvotes: 0

TechGuy
TechGuy

Reputation: 4570

Surely a problem is js file is caching.Do CTRL + F5 and then check.If the problem still occured you must clear the whole browser cache.

Upvotes: 2

Related Questions