DataAnnotations page 62...

May 26, 2010 at 4:27 AM
Edited May 26, 2010 at 4:57 AM

On this page the tutorial tells me to add an Album class to the Models folder. So far so good.

However when I enter this line...

 

 [MetadataType(typeof(AlbumMetaData))]

 

I get an error on AlbumMetaData which says..

 

The type or namespace name 'AlbumMetaData' could not be found (are you missing a using directive or an assembly reference). 

 

I'm pretty sure I am not missing either.

So far I have followed the tutorial word by word and it has all worked as expected. But now I am stuck on page 62 .

What am I missing?

Cheers.

BTW: this is my first crack at MVC and this is a super tutorial. Mind you, coming for ASP.NET 2.0 to this I get the felling I am going to need to read it all again once done.

 

Jun 1, 2010 at 7:05 AM

you are missing class AlbumMetaData (on page 62 it's an internal class inside Album). Maybe you misspelled it?

 

Dec 6, 2010 at 7:56 PM

I am having the same issue.  There is no referrence to creating an AlbumnMetaData class anywhere in the turorial.  Page 62 is not even related to validation.  Where can I find the code to create this class for this project?

Thanks!!!

Coordinator
Dec 6, 2010 at 10:24 PM

AlbumMetaData is described on page 98 of the v1 PDF, in section 6. You can see this online here: http://www.asp.net/mvc/tutorials/mvc-music-store-part-6

Here's the code for that class:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
 
namespace MvcMusicStore.Models
{
    [MetadataType(typeof(AlbumMetaData))]
    public partial class Album
    {
        // Validation rules for the Album class
 
        [Bind(Exclude = "AlbumId")]
        public class AlbumMetaData
        {
            [ScaffoldColumn(false)]
            public object AlbumId { get; set; }
 
            [DisplayName("Genre")]
            public object GenreId { get; set; }
 
            [DisplayName("Artist")]
            public object ArtistId { get; set; }
 
            [Required(ErrorMessage = "An Album Title is required")]
            [StringLength(160)]
            public object Title { get; set; }
 
            [DisplayName("Album Art URL")]
            [StringLength(1024)]
            public object AlbumArtUrl { get; set; }
 
            [Required(ErrorMessage = "Price is required")]
            [Range(0.01, 100.00, 
                ErrorMessage = "Price must be between 0.01 and 100.00")]
            public object Price { get; set; }
        }
    }
}
Dec 7, 2010 at 12:33 PM
Edited Dec 7, 2010 at 12:41 PM

Thanks for the info!!