Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 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 April 22nd, 2019, 03:02 PM
Authorized User
Points: 189, Level: 3
Points: 189, Level: 3 Points: 189, Level: 3 Points: 189, Level: 3
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2005
Location: Brandon, MS, USA.
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default chapter 14 Page 525 error

I get an error on page 525 when attempting to run ManagePhotoAlbum.aspx in the browser. It is in step 2 of the Try It Out example on that page. The error looks like the following Please let me know what I am doing wrong there...maybe I am not supposed to open ManagePhotoAlbum.aspx in the browser yet please let mew know:Server Error in '/' Application.

A null value for parameter 'photoAlbumId' of non-nullable type 'System.Int32' for method 'System.Linq.IQueryable ListView1_GetData(Int32)' in '_ManagePhotoAlbum'. An optional parameter must be a reference type or a nullable type.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: A null value for parameter 'photoAlbumId' of non-nullable type 'System.Int32' for method 'System.Linq.IQueryable ListView1_GetData(Int32)' in '_ManagePhotoAlbum'. An optional parameter must be a reference type or a nullable type.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:

[InvalidOperationException: A null value for parameter 'photoAlbumId' of non-nullable type 'System.Int32' for method 'System.Linq.IQueryable ListView1_GetData(Int32)' in '_ManagePhotoAlbum'. An optional parameter must be a reference type or a nullable type.] System.Web.UI.WebControls.ModelDataSourceView.Vali dateParameterValue(ParameterInfo parameterInfo, Object value, MethodInfo methodInfo) +2494081 System.Web.UI.WebControls.ModelDataSourceView.Eval uateMethodParameters(DataSourceOperation dataSourceOperation, ModelDataSourceMethod modelDataSourceMethod, IDictionary controlValues, Boolean isPageLoadComplete) +1304 System.Web.UI.WebControls.ModelDataSourceView.Eval uateMethodParameters(DataSourceOperation dataSourceOperation, ModelDataSourceMethod modelDataSourceMethod, IDictionary controlValues) +20 System.Web.UI.WebControls.ModelDataSourceView.Eval uateSelectMethodParameters(DataSourceSelectArgumen ts arguments, ModelDataSourceMethod method, Boolean isAsyncSelect, DataSourceSelectResultProcessingOptions& selectResultProcessingOptions) +577 System.Web.UI.WebControls.ModelDataSourceView.Eval uateSelectMethodParameters(DataSourceSelectArgumen ts arguments, DataSourceSelectResultProcessingOptions& selectResultProcessingOptions) +17 System.Web.UI.WebControls.ModelDataSourceView.GetS electMethodResult(DataSourceSelectArguments arguments) +62 System.Web.UI.WebControls.ModelDataSourceView.Exec uteSelect(DataSourceSelectArguments arguments) +15 System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +22 System.Web.UI.WebControls.ModelDataSourceView.Sele ct(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +80 System.Web.UI.WebControls.DataBoundControl.Perform Select() +143 System.Web.UI.WebControls.ListView.PerformSelect() +102 System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +74 System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +114 System.Web.UI.WebControls.ListView.CreateChildCont rols() +52 System.Web.UI.Control.EnsureChildControls() +92 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +160 System.Web.UI.Control.PreRenderRecursiveInternal() +160 System.Web.UI.Control.PreRenderRecursiveInternal() +160 System.Web.UI.Control.PreRenderRecursiveInternal() +160 System.Web.
UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883

__________________
Cullan crothers

Last edited by cullancrothers; April 22nd, 2019 at 03:11 PM..
Reply With Quote
  #2 (permalink)  
Old April 22nd, 2019, 07:18 PM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 60%
Activity: 60% Activity: 60% Activity: 60%
 
Join Date: Mar 2019
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Ditto, I'm having the same problem. It's just that NOTHING from Chapter 14 is working. Even when I copy the author's Chapter 13 code and follow every single step in Chapter 14, I get it crashing right and left with one error after another.
Reply With Quote
  #3 (permalink)  
Old April 22nd, 2019, 07:20 PM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 60%
Activity: 60% Activity: 60% Activity: 60%
 
Join Date: Mar 2019
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Have you also experienced VS rejecting both the QueryString() and TryUpdateModel() methods? When I try to build the site I get red underlines for both of them.
Reply With Quote
  #4 (permalink)  
Old April 22nd, 2019, 07:23 PM
Authorized User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 60%
Activity: 60% Activity: 60% Activity: 60%
 
Join Date: Mar 2019
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Default

https://www.dropbox.com/s/2626odkoyk...Error.jpg?dl=0
Reply With Quote
  #5 (permalink)  
Old April 23rd, 2019, 05:15 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Did you add a using / imports statement for the namespace? Page 515, Step 6 has this:

Quote:
To implement this functionality, modify that method as follows. Note that you need to add a using/Imports statement for the namespace System.Web.ModelBinding to bring the QueryString attribute into scope. You can either type in this namespace manually at the top of the code file, or you can press Ctrl+. (Ctrl+dot) on the word QueryString in the method definition and pick the namespace from the list that appears.
Does that fix the issue?

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
  #6 (permalink)  
Old April 23rd, 2019, 11:18 AM
Authorized User
Points: 189, Level: 3
Points: 189, Level: 3 Points: 189, Level: 3 Points: 189, Level: 3
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2005
Location: Brandon, MS, USA.
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default page 525 errors in step 2

The only problem that I am having in chapter 14 is that step 2 on page 525, but then I notice that it does not say to open ManagePhotoAlbum.aspx in the browser. I get that error that I posted when I try to open that page only in the browser. The other pages seem to open fine for me, even the NewPhotoAlbum.aspx page later in that same example works fine. It is just when I try to open ManagePhotoAlbum.aspx in the browser that I get that error. (A null value for parameter 'photoAlbumId' of non-nullable type 'System.Int32' for method 'System.Linq.IQueryable ListView1_GetData(Int32)' in '_ManagePhotoAlbum'. An optional parameter must be a reference type or a nullable type.).

I do have the namespace System.Web.ModelBinding on the code behind file using list for that file. Thanks!
__________________
Cullan crothers
Reply With Quote
  #7 (permalink)  
Old April 25th, 2019, 04:21 AM
Imar's Avatar
Wrox Author
Points: 72,022, Level: 100
Points: 72,022, Level: 100 Points: 72,022, Level: 100 Points: 72,022, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,076
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
It is just when I try to open ManagePhotoAlbum.aspx in the browser that I get that error. (A null value for parameter 'photoAlbumId' of non-nullable type 'System.Int32' for method 'System.Linq.IQueryable ListView1_GetData(Int32)' in '_ManagePhotoAlbum'. An optional parameter must be a reference type or a nullable type.).
That's somewhat by design. ManagePhotoAlbum needs an ID of a photo album to work with in the query string. When it's not there, it'll crash currently.

Some solutions:

1. Don't browse to this page directly, but only from other pages where the ID if the Photo Album is sent along

2. Append the Photo Album ID to the query string. For example:

/ManagePhotoAlbum?PhotoAlbumId=123

where 123 is the ID of an existing album.

3. Write some protective code in the code behind that redirects the user some place else when no ID is present. For example:

Code:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If String.IsNullOrEmpty(Request("PhotoAlbumId"))
      Response.Redirect("SomeOtherPage.aspx")
    End If
End Sub
Code is in VB as I had a VB project open but I think you'll get the idea.

Note: I tried to warn about this situation with the following comment in step 10 on page 517:

Quote:
Make sure you don’t accidentally open ManagePhotoAlbum.aspx, because it requires a query string that is sent by NewPhotoAlbum.aspx.
__________________
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!

Last edited by Imar; April 27th, 2019 at 03:12 AM..
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
cullancrothers (April 26th, 2019)
  #8 (permalink)  
Old April 25th, 2019, 02:25 PM
Authorized User
Points: 189, Level: 3
Points: 189, Level: 3 Points: 189, Level: 3 Points: 189, Level: 3
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2005
Location: Brandon, MS, USA.
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default That is what I was thinking

Thanks much! That is what I thought was happening. I just read the directions wrong when I thought I was supposed to open the page in the browser, when I was not supposed to. All other pages work fine, so all is well.
Thanks;


Cullan
__________________
Cullan crothers
Reply With Quote
  #9 (permalink)  
Old April 26th, 2019, 04:20 PM
Authorized User
Points: 189, Level: 3
Points: 189, Level: 3 Points: 189, Level: 3 Points: 189, Level: 3
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2005
Location: Brandon, MS, USA.
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
Default Page 525 error Solved

I just added the code protected void Page_Load(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Request["PhotoAlbumId"]))
{
Response.Redirect("Default.aspx");
}
}
to ManagePhotoAlbum.aspx.cs to cover the condition for having no PhotoAlbumId variable when the page loads. It is just the C# version of the code that Imar recommended in the above reply.


Cullan
__________________
Cullan crothers
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
Error in Chapter 2 page 50 'Try it Out' damac BOOK: Beginning Android Application Development 1 November 2nd, 2011 04:18 PM
Chapter 4 - Page 114-115 ERROR learner800 BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 February 19th, 2011 02:01 PM
Chapter 9 Try It Out Error, page 325 VictorVictor BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 March 22nd, 2006 02:22 PM
Chapter 10, Try It Out error, page 380 VictorVictor BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 February 13th, 2006 12:41 PM
Chapter 15 page 662 error lance BOOK: Beginning ASP 3.0 0 February 12th, 2004 08:56 PM



All times are GMT -4. The time now is 04:22 AM.


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