Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Beginning ASP.NET Web Pages with WebMatrix
|
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 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 February 28th, 2013, 02:54 PM
Registered User
 
Join Date: Feb 2013
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!)?
 
Old February 28th, 2013, 03:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old February 28th, 2013, 05:41 PM
Registered User
 
Join Date: Feb 2013
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
 
Old March 2nd, 2013, 07:38 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old May 12th, 2017, 08:21 AM
Registered User
 
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





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 12:42 PM
Sugestion for Chapter 10 LINQ section mangel BOOK: Professional Visual Basic 2010 and .NET 4 0 April 4th, 2011 04:41 PM
Passing a hardcoded value and manipulating data before passing it to Database table Abhishek Iyer Biztalk 0 August 17th, 2010 06:45 AM
Passing Data Using Data/Bye Streams d-mart Java Basics 1 April 23rd, 2009 12:20 PM





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