Hello Jon,
While I understand your book isn't intended to be an in depth tutorial on AJAX (I will ultimately purchase an AJAX book), I don't seem to be able to follow some of the introductory level material.
I created a 'Sandbox' View page as follows and it works as expected, it hides the h2 element when I mouse over it.
Code:
@Code
ViewData("Title") = "Sandbox"
End Code
<script src="~/scripts/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$("h2").hover(function () {
$ (this).hide();
});
});
</script>
<h2>Sandbox</h2>
<p id="p1">This is a paragraph.</p>
(I'm reading Kindle, so no page numbers)
Just after Figure 8.1 the book explained the <script src=... concept as shown above. But just after that it states the following can be used instead for a variety of benefits:
Code:
@Scripts.Render("~/bundles/jquery")
The text specifically suggests to use this approach in the _Layout.cshtml file. But in that file the line above is near the bottom of the page. When I remove my <script src="~/scripts/jquery-1.10.2.
js"></script> from the file in order to make use of the 'Render' line shown above, I get an "Unhandled exception error" because " '$' " is undefined. The following does, however, work.
Code:
@Code
ViewData("Title") = "Sandbox"
End Code
@Scripts.Render("~/bundles/jquery")
<script>
$(document).ready(function () {
$("h2").hover(function () {
$ (this).hide();
});
});
</script>
<h2>Sandbox</h2>
<p id="p1">This is a paragraph.</p>
Being new to AJAX, I'm sure this is a basic question, but the book doesn't really address what must be some assumed knowledge about making this work by relying on the _Layout.cshtml code.
Can you shed some light?
Thanks.
Best Regards,
Alan