p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET MVC 2 (http://p2p.wrox.com/forumdisplay.php?f=588)
-   -   NerdDinner Dinner.cs errors (System.ComponentModel.DataAnnotations?) (http://p2p.wrox.com/showthread.php?t=82099)

LorenMaxwell January 2nd, 2011 04:06 AM

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:


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


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

namespace NerdDinner.Models

    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:


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?

LorenMaxwell January 2nd, 2011 04:12 AM

Fixed my own error

Just realized I was missing the


using System.ComponentModel.DataAnnotations;

All times are GMT -4. The time now is 04:47 PM.

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