背景
这是一个后续问题最初的问题 https://stackoverflow.com/questions/60223804/multiple-routes-to-the-same-razor-page/60257348我询问了 asp.net core v3.1 razor 页面路由。
我按照解决方案中的建议将以下内容添加到启动中here https://stackoverflow.com/a/60257348/6479619这使我能够以我想要的两种方式路由到剃刀页面:
services.AddMvc()
.AddRazorPagesOptions(options =>
options.Conventions.AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signup")
);
/identity/account/signup
/identity/account/signupandapply/<fooapplyid>
Issue
我正在努力使用锚标记助手来尊重路径路线/identity/account/signupandapply/<fooapplyid>
。 href 显示使用参数代替/identity/account/signupandapply?fooapplyid=<fooapplyid>
。这是我的锚标记帮助器标记:
<a asp-area="identity" asp-page="/account/signupandapply" asp-route-fooapplyid="@Model.FooApplyId">Apply here</a>
目前,我正在手动设置 href,但想知道如何使用标签助手来使其工作。
<a href="/identity/account/signupandapply/@Model.FooApplyId">Apply here</a>
Note:锚标记被添加到标识区域之外的视图中。
尝试过
我尝试添加下面的内容,显示我想要的 href 。 IE/identity/account/signupandapply/<fooapplyid>
.AddAreaPageRoute("Identity", "/account/signupandapply", "/identity/account/signupandapply/{applyid}")
但是当我转到该页面时出现错误,这是有道理的
AmbiguousMatchException: The request matched multiple endpoints. Matches: /Account/SignUpAndApply /Account/SignUpAndApply
这些都不起作用,href 仍然显示为 ?applyid=:
.AddAreaPageRoute("Identity", "/account/signupandapply?applyid=", "/identity/account/signupandapply/{applyid}")
.AddAreaPageRoute("Identity", "/account/signupandapply/{applyid?}", "/identity/account/signupandapply/{applyid}")
Question
是否还有需要定义的进一步启动路线,或者如何让锚标记助手尊重路径路线?