The following tutorial is based on "Get started with ASP.NET Core Razor Pages in Visual Studio Code" from docs.microsoft.com.
- .NET 7 SDK
- Visual Studio Code
- Tutorial 1- Create a Razor Page application
- Tutorial 2- Add a Model
In this tutorial, you're going to learn how to update the generated pages. For example, suppose you want to remove the time from the release date.
-
Open the
Models/Movie.cs
file. -
Add the following using statements to the top of the file:
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema;
-
Add the following data annotations:
[Display(Name = "Release Date")]
and[DataType(DataType.Date)]
to theReleaseDate
property as shown in the following code:using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace RazorPagesMovie.Models; public class Movie { public int ID { get; set; } public string? Title { get; set; } [Display(Name = "Release Date")] [DataType(DataType.Date)] public DateTime ReleaseDate { get; set; } public string? Genre { get; set; } [Column(TypeName = "decimal(18, 2)")] public decimal Price { get; set; } }
-
Run the app using the
dotnet run
command. -
Navigate to
https://localhost:{port}/Movies/Create
and notice the changes.
NEXT TUTORIAL: Adding search