The following tutorial is based on "Get started with Razor Pages in ASP.NET Core" from docs.microsoft.com.
- Visual Studio 2022 for Mac Preview
- In the Visual Studio for Mac Installer, install the .NET Core target.
- 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. -
Replace the contents of the
Movie.cs
file with the following code: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; } }
-
Select using System.ComponentModel.DataAnnotations;.
-
Right click on the remaining red line, select Quick Actions and Refactorings on the [Column] attribute.
-
Select using System.ComponentModel.DataAnnotations.Schema;.
-
Run the application by selecting Debug > Start without Debugging on the main menu.
-
Navigate to
https://localhost:{port}/Movies/Create
and notice the changes.
NEXT TUTORIAL: Adding search