无法使用定位标记帮助程序来获取剃须刀页面路由 [英] Can't get razor page route to work using anchor tag helper
问题描述
背景
这是对初始问题的后续报道>我询问了asp.net核心v3.1剃须刀页面路由.
This is a follow on issue to an initial question I asked around asp.net core v3.1 razor page routes.
我根据解决方案此处的建议,将以下内容添加到了启动程序中,这使我可以转到以下位置的剃须刀页面我想要的两种方式:
I added the following to the startup as suggested in the solution here which allowed me to route to the razor page in both ways I wanted:
services.AddMvc()
.AddRazorPagesOptions(options =>
options.Conventions.AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signup")
);
/identity/account/signup
/identity/account/signupandapply/<fooapplyid>
问题
我正在努力使用定位标记帮助程序来遵守路径路由/identity/account/signupandapply/<fooapplyid>
. href显示使用参数代替/identity/account/signupandapply?fooapplyid=<fooapplyid>
.这是我的锚标记助手标记:
I'm struggling to use the anchor tag helper to respect the path route /identity/account/signupandapply/<fooapplyid>
. The href shows using the parameter instead /identity/account/signupandapply?fooapplyid=<fooapplyid>
. This is my anchor tag helper markup:
<a asp-area="identity" asp-page="/account/signupandapply" asp-route-fooapplyid="@Model.FooApplyId">Apply here</a>
当前,我正在手动设置href,但是想知道如何使用标签助手来实现此功能.
Currently, I'm manually setting the href but would like to know how to get this working using the tag helper.
<a href="/identity/account/signupandapply/@Model.FooApplyId">Apply here</a>
注意::定位标记已添加到标识区域之外的视图中.
Note: The anchor markup is being added to a view outside of the identity area.
尝试
我尝试添加以下显示所需的href的内容.即/identity/account/signupandapply/<fooapplyid>
I've tried adding the below which shows the href as I want. I.e /identity/account/signupandapply/<fooapplyid>
.AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signupandapply/{applyid}")
但是当我转到页面时,我得到了一个错误,
But I then get an error when I go to the page, which makes sense
AmbiguousMatchException: The request matched multiple endpoints. Matches: /Account/SignUpAndApply /Account/SignUpAndApply
以上两项都不起作用,href仍显示为?applyid =:
Neither of these work, the href still shows as ?applyid=:
.AddAreaPageRoute("Identity", "/account/signupandapply?applyid=", "/identity/account/signupandapply/{applyid}")
.AddAreaPageRoute("Identity", "/account/signupandapply/{applyid?}", "/identity/account/signupandapply/{applyid}")
问题
是否还有一条需要定义的启动路线,或者如何使锚标记帮助程序尊重路径路线?
Is there a further startup route that needs defining or how do I get the anchor tag helper to respect the path route?
推荐答案
AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signup")