我试图在html结果中向锚点添加请求查询中的任何内容:
虚构的例子:
用户发出请求(请注意,乐队和歌曲可以是任何内容,我有一条路径来满足此请求:模板:"{band}/{song}"):
http://mydomain/band/song?Param1=111&Param2=222
Run Code Online (Sandbox Code Playgroud)
现在我希望我的锚点将查询字符串部分附加到我的锚点的href.所以我试过这样的事情(注意'asp-all-route-data'):
<a asp-controller="topic" asp-action="topic" asp-route-band="iron-maiden" asp-route-song="run-to-the-hills" asp-all-route-data="@Context.Request.Query.ToDictionary(d=>d.Key,d=>d.Value.ToString())">Iron Maiden - Run to the hills</a>
Run Code Online (Sandbox Code Playgroud)
查询字符串的附加实际上与上面的代码一起使用,但随后结果中丢失了"铁娘子"和"跑到山上".上面的标签助手返回以下内容(注意帮助器如何将请求中的乐队和歌曲镜像到href中,而不是我在asp-route属性中指定的乐队和歌曲):
<a href="http://mydomain/band/song?Param1=111&Param2=2222">Iron Maiden - Run to the hills</a>
Run Code Online (Sandbox Code Playgroud)
我希望帮助者得到以下结果:
<a href="http://mydomain/iron-maiden/run-to-the-hills?Param1=111&Param2=2222">Iron Maiden - Run to the hills</a>
Run Code Online (Sandbox Code Playgroud)
看起来当我使用asp-all-route-data时,我在结果中丢失了asp-route-band和asp-route-song值.
有没有人偶然发现了这个?
谢谢
Hooroo
asp.net asp.net-mvc tag-helpers asp.net-core asp.net-core-tag-helpers