Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 16th, 2014, 06:24 PM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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..
Reply With Quote
  #2 (permalink)  
Old November 18th, 2014, 04:17 PM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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?
Reply With Quote
The Following User Says Thank You to rfalanga For This Useful Post:
AlanWheeler (January 11th, 2015)
  #3 (permalink)  
Old January 11th, 2015, 01:27 AM
Wrox Author
Points: 165, Level: 3
Points: 165, Level: 3 Points: 165, Level: 3 Points: 165, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: San Diego, CA, USA
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?
Reply With Quote
The Following User Says Thank You to JonGalloway For This Useful Post:
AlanWheeler (January 11th, 2015)
  #4 (permalink)  
Old January 11th, 2015, 02:19 AM
Authorized User
Points: 416, Level: 7
Points: 416, Level: 7 Points: 416, Level: 7 Points: 416, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:52 AM.


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