I am using Razor Pages, and everything has been going smoothly so far.
Now I wish to create a page with an override route. Like the override routes that are shown possible here.
I am, however encountering the following exception, despite I don't seem to have the issue in my code that it describes:
RoutePatternException: There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character.
I must be somehow misunderstanding how this routing works, but I haven't been able to find someone encountering the same issue in my preliminary searches.
This is my entire code on this page so far:
@page "/layouts/{layoutId:int}/save/{revisionId:int}"
@model Project.Web.Pages.TenantBased.Layouts.SavePageModel
@{
Layout = "_TenantLayout";
ViewData["Title"] = "Title";
}
And this is the code-behind:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Legalit.Web.Pages.TenantBased.Layouts
{
public class SavePageModel : PageModel
{
public void OnGet(int layoutId, int revisionId)
{
}
}
}
This gives the following exception when running the project:
RoutePatternException: There is an incomplete parameter in the route template. Check that each '{' character has a matching '}' character.
If I remove the first /
from the route as so:
@page "layouts/{layoutId:int}/save/{revisionId:int}"
Then it stops generating the exception, but I of course get the wrong routing from it. Now my page is reachable by the directory path with this route added to the end of it.
I am using .NET 6.0.
The project type is Microsoft.NET.Sdk.Web
CodePudding user response:
The project had a custom Convention in the Program.cs
that was specified under the AddRazorPagesOptions
configuration method.
After removing this, it worked fine.