Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Professional ASP.NET MVC 2
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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?
  #2 (permalink)  
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.
 


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
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



All times are GMT -4. The time now is 05:45 PM.


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