i making start on including jquery in mvc application.
the following code present:
home controller:
namespace tutorial.controllers { public class homecontroller : controller { [httpget] // /home/index/ public actionresult index() { viewbag.title = "javascript"; return view(); } } }
_layout:
<html> <head> <title>@viewbag.title</title> <link href="@url.content("~/content/site.css")" rel="stylesheet" type="text/css" /> <script src="@url.content("~/scripts/jquery-1.5.1.min.js")" type="text/javascript"> </script> <script src="@url.content("~/scripts/modernizr-1.7.min.js")" type="text/javascript"></script> </head> <body> @renderbody() </body> </html> view:
content <script src="@url.content("~/scripts/init.js")" type="text/javascript"></script> init.js
$(document).ready(function () { alert("document ready"); }); yet when launch no alert appears. have looked @ source code:
index.html
<html> <head> <title>javascript</title> <link href="/content/site.css" rel="stylesheet" type="text/css" /> <script src="/scripts/jquery-1.5.1.min.js" type="text/javascript"></script> <script src="/scripts/modernizr-1.7.min.js" type="text/javascript"></script> </head> <body> content <script src="/scripts/init.js" type="text/javascript"></script> </body> </html> and javascript file rendered:
init.js
$(document).ready(function () { }); as can see alert function missing. idea why not being redered? in advance.
edit: ive updated code joe's responce same problem occurs
you'll need render this
<script type = "text/javascript" src="../../scripts/init.js"></script> after jquery reference , you're doing before far understand code. use script section that.
default _layout comes section in place. on page, should have.
@section scripts { <script type = "text/javascript" src="../../scripts/init.js"></script> }
Comments
Post a Comment