8. Add a Model

Create a Model File

Step 1: Add a file named Movie.cs to the Models folder.

Update the Models/Movie.cs file with the following code:

Movie.cs
using System.ComponentModel.DataAnnotations;

namespace MvcMovie.Models
{
    public class Movie
    {
        public int Id { get; set; }
        public string? Title { get; set; }

        [DataType(DataType.Date)]
        public DateTime ReleaseDate { get; set; }
        public string? Genre { get; set; }
        public decimal Price { get; set; }
    }
}

The Movie class contains an Id field, which is required by the database for the primary key.

The DataTypearrow-up-right attribute on ReleaseDate specifies the type of the data (Date). With this attribute:

  • The user isn't required to enter time information in the date field.

  • Only the date is displayed, not time information.

Install Model Design Softwares

Step 2:

Step 3:

Step 4:

Step 5:

Step 6:

Step 7:

Last updated