[英]How to Generate href from razor pages using anchor tag helpers?
I am using razor pages and.net 5.0 My page name is Edit.cshtml
which has page directive url as @page /p/{id}
我正在使用 razor 页面和 .net 5.0 我的页面名称是
Edit.cshtml
,它有页面指令 url 作为@page /p/{id}
Now from another page I want to generate put a anchor tag to this page I know we can just do it by现在我想从另一个页面生成一个锚标记到这个页面我知道我们可以通过
<a href="/p/id">
but I want to generate it with anchor tage helper in .net lik asp-page, asp-route但我想在 .net lik asp-page, asp-route 中使用 anchor tage helper 生成它
beacuse here my page name and route is different I can't generate.因为这里我的页面名称和路由不同,所以我无法生成。
Is there any other way to generate it?还有其他生成方法吗?
It doesn't matter, if your page directive differs from your page name.没关系,如果您的页面指令与您的页面名称不同。
If your page is called "Edit" with a route /p/{id}
create a tag helper like this:如果您的页面被称为“编辑”并带有路由
/p/{id}
创建一个标签助手,如下所示:
<a asp-page="/Edit" asp-route-id="3">Click here to edit things.</a>
This will generate the following markup这将生成以下标记
<a href="/p/3">Click here to edit things.</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.