Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
|
BOOK: Professional ASP.NET MVC 2
This is the forum to discuss the Wrox book Professional ASP.NET MVC 2 by Jon Galloway, Scott Hanselman, Phil Haack, Scott Guthrie, Rob Conery; ISBN: Professional ASP.NET MVC 2
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 2 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 January 2nd, 2011, 04:06 AM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default NerdDinner Dinner.cs errors (System.ComponentModel.DataAnnotations?)

I am working my way through the NerdDinner tutorial and am held up at the creation of the Dinner.CS page. When I enter the code from the book or even cut and paste from the code download, I get the MetadataType, Required, and StringLength words underlined in red and 16 errors, all being similar to:

Quote:
The type or namespace name 'MetadataType' could not be found (are you missing a using directive or an assembly reference?)
My code is:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NerdDinner.Models
{

     [MetadataType(typeof(Dinner_Validation))]
    public partial class Dinner {
      //...
    }
    public class Dinner_Validation
    {
        [Required(ErrorMessage = "Title is required")]
        [StringLength(50, ErrorMessage = "Title may not be longer than 50 characters")]
        public string Title { get; set; }

        [Required(ErrorMessage = "Description is required")]
        [StringLength(256, ErrorMessage = 
          "Description must be 256 characters or less")]
        public string Description { get; set; }

        [Required(ErrorMessage = "Address is required")]
        public string Address { get; set; }

        [Required(ErrorMessage = "Country is required")]
        public string Country { get; set; }

        [Required(ErrorMessage = "Phone# is required")]
        public string ContactPhone { get; set; }
    }

}
The paragraph on page 33 before the above code states:

Quote:
ASP.NET MVC 2 introduces support for Data Annotations validation attributes. These are a set of attributes that live in the System.ComponentModel.DataAnnotations namespace and were introduced as part of the Dynamic Data feature of ASP.NET 3.5 Service Pack 1. To use these attributes, make sure to reference the System.ComponentModel.DataAnnotations.dll assembly from the .NET tab of the Add Reference dialog. Note that this assembly is referenced by default when creating new ASP.NET MVC 2 projects in Visual Studio.

From what I can see from the References list in the solution explorer, I have System.ComponentModel.DataAnnotations installed, but it seems to me like the program doesn’t think it is.

Any thoughts?
 
Old January 2nd, 2011, 04:12 AM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Fixed my own error



Just realized I was missing the

Code:
using System.ComponentModel.DataAnnotations;
statement.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 - NerdDinner - Errors Steve S BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 17 May 22nd, 2010 03:22 PM
ShoppingCart.aspx.cs - System.FormatException ??? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 April 16th, 2008 01:00 AM
System.Transactions in Orders.cs rparchment BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 November 3rd, 2006 10:49 PM
System.ComponentModel.Win32Exception: Access is de soumya1979 Visual Studio 2005 0 April 19th, 2006 01:12 AM





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