TagHelper,用于将路径值作为链接的一部分传递 [英] TagHelper for passing route values as part of a link

查看:55
本文介绍了TagHelper,用于将路径值作为链接的一部分传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在链接上指定asp-controllerasp-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆