问题描述
我无法在ASP.NET Core 2.2应用程序中为Razor Pages设置路由约定(我正在从传统的MVC迁移到Razor Pages).
I'm having trouble setting up a routing convention for Razor Pages in an ASP.NET Core 2.2 application (I'm migrating from traditional MVC to Razor Pages).
我使用的是文档中建议的标准Pages文件夹结构,但是我想稍微自定义生成的路由.
I am using the standard Pages folder structure as recommended in the documentation, but I want to customise the generated routes slightly.
例如,在Products文件夹中的Details.cshtml页面上,我具有以下指令:
For example, on a Details.cshtml page in the Products folder I have the following directive:
@page "{id:int}
此页面的网址是:
/Products/Details/42
但是我希望URL为:
/Products/42
我希望这在全球范围内适用,而不仅仅是在产品详细信息"页面上.该文档对此并不特别清楚.
I want this to be globally applicable, not just on the Product Details page. The documentation is not particularly clear on this.
推荐答案
您需要覆盖整个路线,所以这就是您需要的-
You need to override the entire route, so this is what you needed -
@page "/Products/{id:int}"
这篇关于ASP.NET Core 2.2剃刀页中的自定义路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!