Usually I create a javascript file (myfile.js) for my scripts.
Example:
/// <reference path="../../Scripts/Jquery/jquery-1.5.1.js" />
$(document).ready(function () {
// bind 'myForm' and provide a simple callback function
$('#uploadBackgroundForm').ajaxForm({
iframe: true,
dataType: "json",
success: BackgroundUploadedSuccess,
error: BackgroundUploadedError
});
});
Now I would like to place my script directly in my view (.cshtml) in a section (< script type=”text/javascript”>…..< / script >).
Example:
...my view goes here...
<script type="text/javascript">
/// <reference path="../../Scripts/jquery-1.5.1.js" />
$(document).ready(function () {
// bind 'myForm' and provide a simple callback function
$('#uploadBackgroundForm').ajaxForm({
iframe: true,
dataType: "json",
success: BackgroundUploadedSuccess,
error: BackgroundUploadedError
});
});
....
</script>
But it doesn’t work. I mean when I place my cursor on a jQuery syntax like ‘ready’ and click CTRL+J nothing is recognised.
Any idea?
Thanks.
You have to add the reference with such construct :
With the
@if (false)the script is not loaded at runtime… (You can also see this page).UPDATE :
You have to insert this code just before your other script tag.