From the references below, it seems that there has been an ongoing problem with hyphens in the filenames for Razor Pages. The bugs below have been documented as fixed, but Add Razor Page still does not permit hyphens, as shown below:
My SEO guy insists that filenames must have hyphens, and if I rename a file later to put a hyphen in, it seems to work fine.
Am I correct in thinking this is a bug? Where should I report it?
References:
https://github.com/aspnet/Mvc/issues/6296
RazorPages with filenames that include a hyphen cause IntelliSense to break
Using dash/hyphen in Razor Page filename – does compile but VS shows errors
2
Answers
Rather than try to battle with a bug or whatever it is, you could use an underscore where the hyphen should go and then use an
IPageRouteModelConvention
implementation to replace the underscore with a hyphen for routing purposes, keeping your SEO guy happy.A suitable implementation might look like this:
Then you just need to register that at Startup:
You can read more about this interface here: https://www.learnrazorpages.com/advanced/custom-route-conventions
You can use the @page directive to explicitly give the route name.