【问题标题】:Routing based on URL parameter in Razor PagesRazor 页面中基于 URL 参数的路由
【发布时间】:2020-04-03 19:26:04
【问题描述】:

这是一个非常简单的问题,但我的搜索没有得到预期的答案。我有一个网址:

http://localhost/customers

显然这会映射到“客户”文件夹中的 Index.cshtml 文件。

我想要另一个网址:

http://localhost/customers/<CustomerID>

映射到另一个页面/Customers/Detail.cshtml

如何在 .NET Core 3.0 中配置路由,以便对 http://localhost/customers/&lt;CustomerID&gt; 的请求路由到 Detail.cshtml?

【问题讨论】:

    标签: asp.net-core routing razor-pages


    【解决方案1】:

    在您的 Details.cshtml 文件中使用覆盖路由:

    @page "/customers/{id:int}"
    

    您可以在此处阅读 Razor 页面中的覆盖路由:https://www.learnrazorpages.com/razor-pages/routing#override-routes

    【讨论】:

    • 完美,这正是我正在寻找的东西,链接帮助很大!对于未来的访问者,链接到此页面的锚标记如下所示:
    猜你喜欢
    • 2018-07-07
    • 2019-12-15
    • 2018-10-16
    • 2020-04-03
    • 2021-04-13
    • 2020-11-16
    • 2020-05-01
    • 1970-01-01
    • 2021-04-16
    相关资源
    最近更新 更多