asp.net-core - Razor 页面中基于 URL 参数的路由
问题描述
这是一个非常简单的问题,但我的搜索没有得到预期的答案。我有一个网址:
http://localhost/customers
显然,这映射到“客户”文件夹中的 Index.cshtml 文件。
我想要另一个网址:
http://localhost/customers/<CustomerID>
映射到另一个页面 /Customers/Detail.cshtml
如何在 .NET Core 3.0 中配置路由,以便将请求http://localhost/customers/<CustomerID>
路由到 Detail.cshtml?
解决方案
在您的Details.cshtml文件中使用覆盖路由:
@page "/customers/{id:int}"
您可以在此处阅读 Razor 页面中的覆盖路由:https ://www.learnrazorpages.com/razor-pages/routing#override-routes
推荐阅读
- java - 如何在 RxJava Observable 中更新数据库?
- python - AttributeError:类型对象'ClassName'没有属性'object'
- keras - 在 Keras 中连接 LSTM 的输出
- android - Scroll and click a textview by matching keyword using Appium
- jquery - 是什么导致此 CodePen Google Maps API 示例在单击时无法正确切换位置?
- mysql - mysql:(pdo)在最后一个位置继续而不使用OFFSET
- javascript - 将传递道具反应到儿童边缘案例?
- xml - 需要在下面的xml中获取标签的xpath
- c# - (Regular Expression) To check start with specified text and next numeric
- javascript - context.filter not working on safari