Sunday 15 January 2012

asp.net mvc - Javascript/jQUERY not working on MVC 4 Visual Studio 2012 project -



asp.net mvc - Javascript/jQUERY not working on MVC 4 Visual Studio 2012 project -

i'm trying utilize jquery create simple menu won't work. javascript utilize on sites either don't work @ or throw errors.

for example, can download solution offered in tutorial below , javascript work downloaded files, not own projects create, if 100% identical.

http://rjdudley.com/creating-a-simple-dynamic-menu-in-asp-net-mvc/

so 1 time again , website above: if follow tutorial, jquery won't work while works downloaded solution.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>@viewbag.title - asp.net mvc application</title> <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> <meta name="viewport" content="width=device-width" /> @styles.render("~/content/css") <link href="../../content/themes/base/jquery.ui.core.css" rel="stylesheet" type="text/css" /> <link href="../../content/themes/base/jquery.ui.menu.css" rel="stylesheet" type="text/css" /> @scripts.render("~/bundles/modernizr") </head> <body> <header> <div class="content-wrapper"> <div class="float-left"> <p class="site-title">@html.actionlink("your logo here", "index", "home")</p> </div> <div class="float-right"> <section id="login"> @html.partial("_loginpartial") </section> <nav> @html.action("menu", "home") </nav> </div> </div> </header> <div id="body"> @rendersection("featured", required: false) <section class="content-wrapper main-content clear-fix"> @renderbody() </section> </div> <footer> <div class="content-wrapper"> <div class="float-left"> <p> &copy; @datetime.now.year - asp.net mvc application</p> </div> </div> </footer> @scripts.render("~/bundles/jquery") @scripts.render("~/bundles/jqueryui") <script> $(document).ready(function () { $("#menu").menu(); }); </script> @rendersection("scripts", required: false) </body> </html>

if using chrome or firefox should able "right click" , "inspect element". should see tab says "console". errors show there. if "$" undefined jquery not loading.

you can see files loaded hitting "sources" tab (in chrome similar in firefox). expand each of sources , see if jquery there. if not have missing.

i find easiest jquery working, adding <script src="~/myjsfile.js"/> straight layout page.

hope helps

jquery asp.net-mvc

No comments:

Post a Comment