MVC Models


Other than the default model file ErrorViewModel.cs, this project creates two model files Book.cs and Author.cs by performing the folllowing tasks. Select the template :


Add a new class Book.cs into the folder with some properties:




 


C:\ASP.NET-workspace\BookStore3\Models\Book.cs
 using System.ComponentModel.DataAnnotations;

 namespace BookStore3.Models {
   public class Book {

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

     [ Display( Name = "Book Title" ) ]
     [ Required ]
     public string Title { 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; }

     public ICollection<Author> Authors { get; set; } = new List<Author>( );
   }
 }




      “The second day of a diet is always easier than the first.    
      By the second day, you’re off it.”    
      — Buddy Hackett