MVC Models: Book.cs

using System.ComponentModel.DataAnnotations;
The namespace provides attribute classes that are used to define metadata for ASP.NET MVC and ASP.NET data controls.

[ Key ]
The attribute from the DataAnnotations namespace is used to designate a property as the primary key of a model class.

[ Required ]
The [Required] attribute from the DataAnnotations namespace is crucial for marking properties as mandatory.

get;
This defines the getter accessor, which is a method that allows you to retrieve (read) the value of the property.

set;
This defines the setter accessor, which is a method that allows you to assign (write) a new value to the property.

[ Display( Name = "Book Title" ) ]
The [Display] attribute is commonly used in models to specify metadata for properties, such as display names, descriptions, or formatting. This is particularly helpful when working with forms or views, as it allows you to customize how data is presented to users.

[ DataType( DataType.Currency ) ]
The [DataType] attribute indicates that the property represents a currency value.

[ Range( 1, 100 ) ]
The [Range] attribute is used to specify the minimum and maximum values for a property in a model.
C:\ASP.NET-workspace\BookStore1\Models\Book.cs
 using System.ComponentModel.DataAnnotations;
 namespace BookStore1.Models {

   public class Book {
     [ Key ]
     [ Required ]
     public int Id { get; set; }

     [ Display( Name = "Book Title" ) ]
     [ Required ]
     public string Title { get; set; }

     public string Genre { get; set; }

     [ DataType( DataType.Currency ) ]
     [ Range( 1, 100 ) ]
     public decimal Price { get; set; }

     [ Display( Name = "Publish Date" ) ]
     [ DataType( DataType.Date ) ]
     public DateTime PublishDate { get; set; }
   }
 }





      “I love being married.    
      It’s great to find that one special person    
      you want to annoy for the rest of your life.”    
      — Rita Rudner