![]() It defines page handlers for requests sent to the page and the data used to render the page. The PageModel class allows separation of the logic of a page from its presentation. If (Customer != null) _(Customer) īy convention, the PageModel class is called Model and is in the same namespace as the page. Public CreateModel(Data.CustomerDbContext context) Private readonly Data.CustomerDbContext _context The Pages/Customers/ page model: public class CreateModel : PageModel The Pages/Customers/Create.cshtml view file: *, Public CustomerDbContext (DbContextOptions options) Public class CustomerDbContext : DbContext The db context: using Microsoft.EntityFrameworkCore Var builder = WebApplication.CreateBuilder(args) The in memory database requires the NuGet package. Consider a page that implements a basic "contact us" form for the Contact model:įor the samples in this document, the DbContext is initialized in the Program.cs file. Model binding, Tag Helpers, and HTML helpers work with the properties defined in a Razor Page class. Razor Pages is designed to make common patterns used with web browsers easy to implement when building an app. Index is the default page when a URL doesn't include a page.The runtime looks for Razor Pages files in the Pages folder by default.The following table shows a Razor Page path and the matching URL: File name and path The associations of URL paths to pages are determined by the page's location in the file system. The file containing the PageModel class is named Pages/. For example, the previous Razor Page is Pages/Index2.cshtml. Public string Message " īy convention, the PageModel class file has the same name as the Razor Page file with. The Pages/Index2.cshtml file: Index2Model cshtml suffix.Ī similar page, using a PageModel class, is shown in the following two files. affects the behavior of other Razor constructs. ![]() must be the first Razor directive on a page. makes the file into an MVC action, which means that it handles requests directly, without going through a controller. What makes it different is the directive. The time on the server is preceding code looks a lot like a Razor view file used in an ASP.NET Core app with controllers and views. MapRazorPages adds endpoints for Razor Pages to the IEndpointRouteBuilder.AddRazorPages adds services for Razor Pages to the app.Razor Pages is enabled in Program.cs: var builder = WebApplication.CreateBuilder(args) See Get started with Razor Pages for detailed instructions on how to create a Razor Pages project. Run dotnet new webapp from the command line.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |