Reputation: 1795
asp.net mvc 3 with razor I have a script inside a partial view
<script type="text/javascript">
function MYFunction()
{
...
</script>
It's working fine
If I move the code inside a .js file and try to load the script with
<script src="path to my script file" type="text/javascript"></script>
The script doesn't execute some code, a jquery.ajax, the rest of the code is executed (I'm debugging inside visual studio)
Any suggestion?
Upvotes: 1
Views: 685
Reputation: 150283
My guess is that you use the '@' symbol and some c# code inside the javascript function and it doesn't work inside js file only in cshtml - razor file.
Am I right?
Upvotes: 2
Reputation: 6111
Ensure your scripts are loading in the proper order. Meaning, if your script uses JQuery then you will have to have the tag loading JQuery BEFORE your script's tag.
Upvotes: 0
Reputation: 215
Try following:
<script type="text/javascript" src="path to my script file">
Upvotes: 0