I have a simple javascript function
function SayTest() {
alert("test");
}
I include the javascript file in my MVC 4 view
<script type="javascript" src="~/Scripts/MyScripts/MyScript.js"></script>
and call the SayTest function from within my view
<script type="text/javascript">
$(document).ready(function () {
$("#myBtn").click(function () {
SayTest();
});
});
</script>
I'm getting an undefined function error. This is driving me nuts. If the js file was included and the function is define, why do I get an undefined function error?
Try using :
<script type="text/javascript" src="~/Scripts/MyScripts/MyScript.js"></script>