From dd23f94aed11d5d54c848633099aad1599ca8af3 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 23 Apr 2018 15:18:41 -0500 Subject: [PATCH] Place RP convention scenarios in context (#6053) * Place RP convention scenarios in context * React to feedback --- .../razor-pages-convention-features.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/aspnetcore/mvc/razor-pages/razor-pages-convention-features.md b/aspnetcore/mvc/razor-pages/razor-pages-convention-features.md index 87906ee3a6..f0734a653a 100644 --- a/aspnetcore/mvc/razor-pages/razor-pages-convention-features.md +++ b/aspnetcore/mvc/razor-pages/razor-pages-convention-features.md @@ -36,6 +36,25 @@ Learn how to use page [route and app model provider convention](xref:mvc/control | [Default page app model provider](#replace-the-default-page-app-model-provider) | Replace the default page model provider to change the conventions for handler names. | ::: moniker-end +Razor Pages conventions are added and configured using the [AddRazorPagesOptions](/dotnet/api/microsoft.extensions.dependencyinjection.mvcrazorpagesmvcbuilderextensions.addrazorpagesoptions) extension method to [AddMvc](/dotnet/api/microsoft.extensions.dependencyinjection.mvcservicecollectionextensions.addmvc) on the service collection in the `Startup` class. The following convention examples are explained later in this topic: + +```csharp +public void ConfigureServices(IServiceCollection services) +{ + services.AddMvc() + .AddRazorPagesOptions(options => + { + options.Conventions.Add( ... ); + options.Conventions.AddFolderRouteModelConvention("/OtherPages", model => { ... }); + options.Conventions.AddPageRouteModelConvention("/About", model => { ... }); + options.Conventions.AddPageRoute("/Contact", "TheContactPage/{text?}"); + options.Conventions.AddFolderApplicationModelConvention("/OtherPages", model => { ... }); + options.Conventions.AddPageApplicationModelConvention("/About", model => { ... }); + options.Conventions.ConfigureFilter(model => { ... }); + options.Conventions.ConfigureFilter( ... ); + }); +} +``` ## Model conventions