Robjocky
Robjocky

Reputation: 47

asp.net mvc get jQuery to work in a view

I'm trying to get jQuery working in my view but I cannot get a simple alert box to appear!

My _Layout page has the default bundles defined before the closing 'body' tag:

 @Scripts.Render("~/bundles/jquery")
 @Scripts.Render("~/bundles/bootstrap")
 @RenderSection("scripts", required: false)
</body>

At the top of my View have a script section:

@section scripts {
<script type=”text/javascript”>
          $(function() {
      alert("hello");
    });
</script>
}

The source code from the rendered page shows this before the closing 'body' tag:

   <script src="/bundles/jquery?v=Aj1GKhwLcrKGfvkl6W3KyVVaqQJQ2zhPCS3xQ5-_xuE1"></script>

   <script src="/bundles/bootstrap?v=2Fz3B0iizV2NnnamQFrx-NbYJNTFeBJ2GM05SilbtQU1">   </script>


<script type=”text/javascript”>
          $(function() {
      alert("hello");
    });
</script>

Why am I not seeing an alert message??

Upvotes: 2

Views: 114

Answers (1)

Jai
Jai

Reputation: 74738

Remove the smart double quotes or should i say curly quotes from here <script type=”text/javascript”>:

@section scripts {
   <script type="text/javascript">
      $(function() {
           alert("hello");
      });
   </script>
}

is different against " double quotes.

Upvotes: 3

Related Questions