Wrox Programmer Forums
|
BOOK: Professional ASP.NET MVC 5
This is the forum to discuss the Wrox book Professional ASP.NET MVC 5 by Jon Galloway, Brad Wilson, K. Scott Allen, David Matson; ISBN: 978-1-118-79475-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 16th, 2014, 06:24 PM
Authorized User
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default Ch 8 AJAX

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

Last edited by AlanWheeler; September 16th, 2014 at 06:28 PM..
 
Old November 18th, 2014, 04:17 PM
Registered User
 
Join Date: Nov 2014
Posts: 8
Thanks: 4
Thanked 1 Time in 1 Post
Default Re: Ch 8 AJAX

Hi Alan,

I don't know the answer to your question, but I'm wondering if you might be missing a reference to the jQuery library in your code?
The Following User Says Thank You to rfalanga For This Useful Post:
AlanWheeler (January 11th, 2015)
 
Old January 11th, 2015, 01:27 AM
Wrox Author
 
Join Date: Oct 2006
Posts: 36
Thanks: 1
Thanked 5 Times in 5 Posts
Default

Alan, as Rod said you're definitely missing the jQuery library. It's possible that you have a different version of jQuery in your scripts folder (other than 1.10.2). Do you see a jQuery file in your /scripts folder?
The Following User Says Thank You to JonGalloway For This Useful Post:
AlanWheeler (January 11th, 2015)
 
Old January 11th, 2015, 02:19 AM
Authorized User
 
Join Date: Nov 2013
Posts: 84
Thanks: 29
Thanked 2 Times in 2 Posts
Default

Thanks for the response, Jon. I'll have to get back to this setup as it was an older post, but when I am able to check this out I'll come back to this forum.

Best Regards,
Alan





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 6-8 Data Annotations, Validation & AJAX AlanWheeler BOOK: Professional ASP.NET MVC 5 0 September 16th, 2014 04:27 PM
Ch 10 AJAX Update Panel and measuring the page weight AlanWheeler BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 January 28th, 2014 10:06 AM
Ajax Problems ch. 27 gigs BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 0 September 24th, 2007 05:50 AM
Recommend an AJAX IDE - JoyiStar AJAX WebShop. kingstar Ajax 4 December 15th, 2006 05:12 AM
new Ajax article: Creating an Ajax Search Widget jminatel Ajax 0 May 11th, 2006 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.