gpt4 book ai didi

asp.net-mvc - MVC - RouteLink 和图像

转载 作者:行者123 更新时间:2023-12-02 06:12:22 25 4
gpt4 key购买 nike

我想要这样的输出:

<a href="\Catalog\Flooring">
<img src="http://site.com/dot.jpg" width="100px" height="100px" alt="" />
<span>Some text here</span>
</a>

使用类似于以下的 RouteLink:

<%= Html.RouteLink(myFPV.ProductTypeName, "CatalogType", new { controller = "Catalog", action = "Types", group = myFPV.ProductGroupName, type = myFPV.ProductTypeName })%>

我不知道如何添加 <img><span> (带文字)我的 <a> 内的标签标签。

有道理吗?

最佳答案

RouteLink 方法的第一个参数用于链接文本。但不幸的是,它会自动编码,因此您无法向其发送 <、> 字符。 (嗯,你可以。但是它们会被编码。)

看看this page .

Route values are URL encoded automatically. For example, the string “Hello World!” is encoded to “Hello%20World!”.

Rendering Image Links

Unfortunately, you can’t use the Html.ActionLink() helper to render an image link. Because the Html.ActionLink() helper HTML encodes its link text automatically, you cannot pass an tag to this method and expect the tag to render as an image.

Instead, you need to use the Url.Action() helper to generate the proper link. Here’s how you can generate a delete link with an image:

<a href="<%= Url.Action("Delete") %>">
<img src="../../Content/Delete.png" alt="Delete" style="border:0px" />
</a>

关于asp.net-mvc - MVC - RouteLink 和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/712593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com