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 February 17th, 2016, 06:54 AM
Registered User
 
Join Date: Oct 2015
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 14 Third Try It Out A Simple Model Binding Application, p.505

In the third task I get the error when creating the album.

Code:
Server Error in '/' Application.

Inserting is not supported unless the InsertMethod is specified. 
  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.NotSupportedException: Inserting is not supported unless the InsertMethod is specified.

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: 
[NotSupportedException: Inserting is not supported unless the InsertMethod is specified.]
   System.Web.UI.WebControls.ModelDataSourceView.EvaluateInsertMethodParameters(IDictionary values, ModelDataSourceMethod method) +2455237
   System.Web.UI.WebControls.ModelDataSourceView.EvaluateInsertMethodParameters(IDictionary values) +11
   System.Web.UI.WebControls.ModelDataSourceView.GetInsertMethodResult(IDictionary values, ModelDataSourceMethod method, Boolean isAsyncMethod, Nullable`1 cancellationToken) +39
   System.Web.UI.WebControls.ModelDataSourceView.GetInsertMethodResult(IDictionary values) +41
   System.Web.UI.WebControls.ModelDataSourceView.ExecuteInsert(IDictionary values) +20
   System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +100
   System.Web.UI.WebControls.ModelDataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +140
   System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) +365
   System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +621
   System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +89
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +82
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +161
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9654230
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
I checked both files NewPhotoAlbum.aspx and NewPhotoAlbum.cs with the source, everything is correct.

Code:
<%@ Page Title="Create New Photo Album" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="NewPhotoAlbum.aspx.cs" Inherits="NewPhotoAlbum" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
    <asp:DetailsView AutoGenerateRows="false" ID="DetailsView1" runat="server" DefaultMode="Insert" SelectMethod="DetailsView1_InsertItem">
        <Fields>
            <asp:BoundField DataField="Name" HeaderText="Name" />
            <asp:CommandField ShowInsertButton="True" ShowCancelButton="false" />
        </Fields>
    </asp:DetailsView>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cpClientScript" runat="Server">
</asp:Content>
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 PlanetWroxTempEntities())
            {
                myEntities.PhotoAlbums.Add(photoAlbum);
                myEntities.SaveChanges();
            }
            Response.Redirect(string.Format("ManagePhotoAlbum?PhotoAlbumId={0}", photoAlbum.Id.ToString()));
        }
    }
}
Strange as that IntellySense automatically creates an event "DetailsView1_GetItem" and not "DetailsView1_InsertItem", despite the fact that specified DefaultMode="Insert". I fixed a "Get" on "Insert" in the manual
Code

Last edited by arvalon; February 17th, 2016 at 06:56 AM..
 
Old February 17th, 2016, 07:26 AM
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,

This is incorrect:

SelectMethod="DetailsView1_InsertItem">

and it should be an InsertMethod:

InsertMethod="DetailsView1_InsertItem">

>> I fixed a "Get" on "Insert" in the manual

Which manual?

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:
arvalon (February 17th, 2016)
 
Old February 17th, 2016, 07:38 AM
Registered User
 
Join Date: Oct 2015
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Imar!
Thanks, I found where I was wrong! I printed the image code from the page 508, there is displayed Select method="".
Page 508
 
Old February 17th, 2016, 07:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah I see, that's a confusing image indeed.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 14,Try it out in page 505 and 513 shameema BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 16 March 29th, 2015 03:27 AM
Chapter 14: Simple EntitySource Application try-it out K_Joe BOOK: Beginning ASP.NET 4 : in C# and VB 7 February 16th, 2014 05:00 PM
Chapter 14 : Mapping data model to an object model robochrish BOOK: Beginning ASP.NET 4 : in C# and VB 8 March 5th, 2013 09:52 AM
Chapter 14: Entity Model Code WILL NOT WORK! pittfurg BOOK: Beginning ASP.NET 4 : in C# and VB 6 February 28th, 2013 07:48 AM
chapter 14 Try It Out pg 505 step #4 arodrigu12 BOOK: Beginning ASP.NET 4 : in C# and VB 3 April 21st, 2011 02:28 PM





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