In external js file, I cant use
url = \"@Url.Action(\"Action\", \"Controller\")\"
//url output : @Url.Action(\"Action\", \"Controller\")
//I get IllegalPat
As accepted answer described, you can not use any C# code in external JS file. Here is what I normally do if I need to pass few controller links to my external .js file.
In C# (.cshtml)
In myfile.js
var _url1;
var _url2;
function initScript(url1, url2) {
_url1 = url1;
_url2 = url2;
// other init. codes...
}