2
votes

I'm working on a .NET Core 2.1 Razor Pages application, and can't figure out why the router isn't matching my expectations. In my application an Orchestration object has a collection of Rules objects. An Orchestration is defined queried at the DB with a Guid.

My Index.cshtml in the Orchestration folder looks like

@page "{id:guid}"
@model Website.Pages.Orchestration.OrchestrationModel

and predictably localhost/Orchestration/{guid} routes to the correct page.

My goal is localhost/Orchestration/{guid}/rule/{ruleId}/edit to hit the Edit.cshtml in the Rule folder. My attempts are close, but .NET is matching Orchestration/rule instead of Orchestration/{guid}/rule. I've tried several incantations trying to add {orchestrationid}/{id} to my Edit.cshtml in the Rule directory, but it's not working. This seems possible, I appreciate any help on what I'm missing.

note rule/Index.cshtml has been renamed to Edit

The Edit.cshtml file looks like

@page "{id}"
@model Website.Pages.Orchestration.Rule.RuleModel

The part that doesn't working is trying to access the child routes

enter image description here

1

1 Answers

1
votes

What you actually want to do is to override the default routing system that relies on matching URLs to file paths. You can do this by specifying an override route template as part of the @page directive. Override route templates are prefixed with an option tilde (~) and a forward slash, so the following should work for you:

@page "/Orchestration/{id:guid}/rule/{ruleId:int}/edit"