Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Beginning ASP.NET Web Pages with WebMatrix
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix 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 Display Modes
  #1 (permalink)  
Old February 28th, 2013, 02:54 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Location: Delft, Netherlands
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Chapter 3 - Passing Data from the Layout to a Section

The code for the Footer as show on the top of page 73 is:

Code:
@RenderPage("~/Shared/_Footer.cshtml", new (Year = DateTime.Now.Year))
This gave me two errors:

(1) "Compiler Error Message: CS1031: Type expected"

And then, after I added a type:

(2) "Compiler Error Message: CS0103: The name 'Year' does not exist in the current context"

The code that worked finally:

Code:
@RenderPage("~/Shared/_Footer.cshtml", new DateTime (Page.Year = DateTime.Now.Year))
I couldn't find the errata, is this an error in the code in the book (which, I think, is very good, in every aspect!)?
Reply With Quote
  #2 (permalink)  
Old February 28th, 2013, 03:06 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

Hi there,

I don't have the book right here with me so I can't check. However, the downloadable code has this:

@RenderPage("~/Shared/_Footer.cshtml", new {Year = DateTime.Now.Year})

Notice it uses curly braces {} around the anonymous type for the date instead if parentheses () as per your example. Maybe it's just a typo?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old February 28th, 2013, 05:41 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Location: Delft, Netherlands
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, you're right, it was the curly brackets (my reading error) that caused the problem. But the solution I found for getting it to work anyway helped me to find a way to use the alternative notation for page data, which gives errors with the curly bracket notation and which I prefer because it stands out clearer in the code:

Code:
@RenderPage("~/Shared/_Footer.cshtml", new DateTime (PageData["Year"] = DateTime.Now.Year))
and in the footer:

Code:
© 2012-@PageData["Year"], SomeName
This works fine, but maybe it is a clumsy way to get this result?

Hans
Reply With Quote
  #4 (permalink)  
Old March 2nd, 2013, 07:38 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

Yes, it's a bit weird. You're creating a new DateTime that you never use, only to assign a year to PageData.

And yes, constructor syntac (e.g. new DateTime(...) uses parentheses instead of the curly braces.

Cheers.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old May 12th, 2017, 09:21 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2017
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Imar
FYI, the book is correct, I made the same typo as I didn't spot the curly braces either.
Nick
Reply With Quote
Reply


Thread Tools
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
Chapter 3 Nested Layout Pages jpjamie BOOK: Beginning ASP.NET Web Pages with WebMatrix 1 December 31st, 2011 04:36 PM
Chapter 14 - Second Try it Out section olias BOOK: Beginning ASP.NET 4 : in C# and VB 3 May 4th, 2011 01:42 PM
Sugestion for Chapter 10 LINQ section mangel BOOK: Professional Visual Basic 2010 and .NET 4 0 April 4th, 2011 05:41 PM
Passing a hardcoded value and manipulating data before passing it to Database table Abhishek Iyer Biztalk 0 August 17th, 2010 07:45 AM
Passing Data Using Data/Bye Streams d-mart Java Basics 1 April 23rd, 2009 01:20 PM



All times are GMT -4. The time now is 10:23 PM.


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