基于 Razor Pages 中 URL 参数的路由
Routing based on URL parameter in Razor Pages
这是一个非常简单的问题,但我的搜索没有得出预期的答案。我有一个 URL:
http://localhost/customers
显然这映射到 "Customers" 文件夹中的 Index.cshtml 文件。
我想要另一个URL:
http://localhost/customers/<CustomerID>
映射到另一个页面/Customers/Detail.cshtml
如何在 .NET Core 3.0 中配置路由,以便对 http://localhost/customers/<CustomerID>
的请求将路由到 Detail.cshtml?
在您的 Details.cshtml 文件中使用覆盖路由:
@page "/customers/{id:int}"
您可以在此处阅读 Razor Pages 中的替代路由:https://www.learnrazorpages.com/razor-pages/routing#override-routes
这是一个非常简单的问题,但我的搜索没有得出预期的答案。我有一个 URL:
http://localhost/customers
显然这映射到 "Customers" 文件夹中的 Index.cshtml 文件。
我想要另一个URL:
http://localhost/customers/<CustomerID>
映射到另一个页面/Customers/Detail.cshtml
如何在 .NET Core 3.0 中配置路由,以便对 http://localhost/customers/<CustomerID>
的请求将路由到 Detail.cshtml?
在您的 Details.cshtml 文件中使用覆盖路由:
@page "/customers/{id:int}"
您可以在此处阅读 Razor Pages 中的替代路由:https://www.learnrazorpages.com/razor-pages/routing#override-routes