开发者

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

开发者 https://www.devze.com 2023-03-27 00:44 出处:网络
asp.net mvc 3 with razor I have a script inside a partial view &l开发者_JAVA百科t;script type=\"text/javascript\">

asp.net mvc 3 with razor I have a script inside a partial view

&l开发者_JAVA百科t;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?


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?


Try following:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消