Rodrigo Juarez
Rodrigo Juarez

Reputation: 1795

Difference between script src and code inside script in asp.net mvc 3 razor partial view executing jquery.ajax

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

Answers (3)

gdoron
gdoron

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

Frazell Thomas
Frazell Thomas

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

Julian S
Julian S

Reputation: 215

Try following:

<script type="text/javascript" src="path to my script file">

Upvotes: 0

Related Questions