TagHelper 用于将路由值作为链接的一部分传递 [英] TagHelper for passing route values as part of a link
本文介绍了TagHelper 用于将路由值作为链接的一部分传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在链接上指定 asp-controller
和 asp-action
时,同时传递 id 属性的语法是什么?
When specifying asp-controller
and asp-action
on a link, what's the syntax for also passing an id attribute?
例如如果我想链接到给定对象的编辑 URL,则所需的 URL 将是 /user/edit/5
例如.
E.g. If I wanted to link to the edit URL for a given object, the required URL would be /user/edit/5
for example.
有没有使用 TagHelpers 的方法来实现这一点,还是我们仍然必须退回到 @Html.ActionLink()
?
Is there a method to achieve this using TagHelpers, or do we still have to fall back to @Html.ActionLink()
?
推荐答案
您可以使用属性前缀 asp-route-
为您的路由变量名称添加前缀.
You can use the attribute prefix asp-route-
to prefix your route variable names.
示例:<a asp-action="Edit" asp-route-id="10" asp-route-foo="bar">Edit</a>
这篇关于TagHelper 用于将路由值作为链接的一部分传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文