MVC Models


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


Add a new class into the folder with some properties:

🡆 🡆 🡆



🡇  


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

   // Principal (parent)
   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; }

     // Collection navigation containing dependents
     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