且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用锚标记助手使剃刀页面路由正常工作

更新时间:2023-12-05 23:24:10

AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signup")

引述 有关此的文档(重点是我的):

To quote the docs on this (emphasis mine):

将指定的route添加到位于指定区域的指定pageName处的页面.

conventions.AddAreaPageRoute(string areaName, string pageName, string route)

Adds the specified route to the page at the specified pageName located in the specified area.

除了默认的基于路径的路由集之外,还可以通过 route 路由页面.为此页面生成的所有链接都将使用指定的路由.

The page can be routed via route in addition to the default set of path based routes. All links generated for this page will use the specified route.

所以这个约定有效地告诉路由从现在开始使用 /identity/acount/signup 路由来生成所有链接,同时接受传入路由来命中两者路线.

So this convention effectively tells the routing to use the /identity/acount/signup route from now on to generate all links, while accepting incoming routes to hit both these routes.

不幸的是,我认为您无法使用页面约定更好地控制这一点.Razor 页面并不真正适合路由模型,在这种模型中,您可以通过不同的路线到达同一页面.毕竟,Razor 页面以页面为中心,而不是像 MVC 操作那样以路由为中心.

Unfortunately, I don’t think that you can control this any better using the page conventions. Razor pages do not really fit a routing model where you are having different route to reach the same page. After all, Razor pages are page-centric instead of route-centric like MVC actions.

因此,如果这对您来说是一个硬性要求,您可能需要考虑在这个用例中使用控制器,而不是呈现相同的视图.就其价值而言,控制器确实可以很好地与使用 Razor 页面的应用程序混合使用.

So if this is a hard requirement for you, you might want to look at using a controller for this one use-case instead that renders the same view. For what it’s worth, controllers do mix nicely with an application that is otherwise using Razor pages.