Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
|
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 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 November 29th, 2016, 12:06 PM
Registered User
 
Join Date: Oct 2016
Posts: 7
Thanks: 5
Thanked 1 Time in 1 Post
Default Chapter 14 Inserting and Deleting Date with the Listview Control

Hi,

Could do with a fresh pair of eyes please.

Have created the web forms NewPhotoAlbum and ManagePhotoAlbum in the root of the Site folder. The NewPhotoAlbum page appears to be working ok and creates a new entry for an album in the PhotoAlbum table.

However I get a 404 error (The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.) at the next line in the code behind of the NewPhotoAlbum page when it calls the ManagePhotoAlbum page.

Here is my code behind:

NewPhotoAlbum.aspx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NewPhotoAlbum : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void DetailsView1_InsertItem()
    {
        PhotoAlbum photoAlbum = new PhotoAlbum();
        TryUpdateModel(photoAlbum);
        if (ModelState.IsValid)
        {
            using (var myEntities = new PlanetWroxEntities())
            {
                myEntities.PhotoAlbums.Add(photoAlbum);
                myEntities.SaveChanges();
            }
            Response.Redirect(String.Format("ManagePhotoAlbum?PhotoAlbumId={0}", photoAlbum.Id.ToString()));
        }
    }
}

ManagePhotoAlbum.aspx.cs

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.ModelBinding;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class ManagePhotoAlbum : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public IQueryable ListView1_GetData([QueryString("PhotoAlbumId")] int photoAlbumId)
    {
        var myEntities = new PlanetWroxEntities();
        return from p in myEntities.Pictures
               where p.PhotoAlbumId == photoAlbumId
               select p;


    }

    public void ListView1_InsertItem([QueryString("PhotoAlbumId")] int photoAlbumId)
    {
        Picture picture = new Picture();
        TryUpdateModel(picture);
        if (ModelState.IsValid)
        {
            using (var myEntities = new PlanetWroxEntities())
            {
                picture.PhotoAlbumId = photoAlbumId;
                myEntities.Pictures.Add(picture);
                myEntities.SaveChanges();
            }
        }
    }

    public void ListView1_DeleteItem(int id)
    {

    }

}

I can't see any typos but to be honest I've been looking at this for so long I can't see the wood from the trees. Has anyone else had this issue?

Thanks in advance.

Harv
 
Old November 29th, 2016, 12:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Do you have friendly URLs enabled? Does it work when you add .aspx to the file name ManagePhotoAlbum in the Redirect call?

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!
The Following User Says Thank You to Imar For This Useful Post:
harvazad (November 29th, 2016)
 
Old November 29th, 2016, 12:39 PM
Registered User
 
Join Date: Oct 2016
Posts: 7
Thanks: 5
Thanked 1 Time in 1 Post
Default

It's all so simple when you know what to look for :-)

Thanks so much Imar.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 - Inserting & Deleting Data with ListView Control hirons BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 1 May 31st, 2016 09:37 AM
Chapter 14: Inserting and Deleting Data with the ListView Control phztfte1 BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 3 January 18th, 2016 04:31 PM
Chapter 14 Inserting and Deleting Data with the ListView Control winkimjr2 BOOK: Beginning ASP.NET 4 : in C# and VB 11 May 18th, 2013 07:29 AM
Chapter 14 errors for Inserting and Deleting Data with the ListView Control winkimjr2 BOOK: Beginning ASP.NET 4 : in C# and VB 7 May 15th, 2013 02:28 PM
Chapter 14, Listview control problem SamuelMSr BOOK: Beginning ASP.NET 4 : in C# and VB 3 September 28th, 2011 02:47 PM





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