如何制作没有文本但内部有图像的 html.actionlink
这是简单的 html:
<%--
<a href="?language=de">
<img src="/Images/Company/de.png" alt="Webseite auf Deutsch" style="border: 0;" />
</a>
--%>
我想用它们制作 html.actionlink:
<%= Html.ActionLink("", "ChangeCulture", "Account", new { lang = "de", returnUrl = this.Request.RawUrl }, new { @style = "background-image: url(/Images/Company/de.png)", @class = "languageLink" }) %>
我想要没有文本的链接。它不起作用,第一个参数为 null 是不允许的。图像与正常情况一样短。我如何使用没有文本但有图像的 html.actionlink ?
it is simple html:
<%--
<a href="?language=de">
<img src="/Images/Company/de.png" alt="Webseite auf Deutsch" style="border: 0;" />
</a>
--%>
i would like to make from them html.actionlink:
<%= Html.ActionLink("", "ChangeCulture", "Account", new { lang = "de", returnUrl = this.Request.RawUrl }, new { @style = "background-image: url(/Images/Company/de.png)", @class = "languageLink" }) %>
I would like to have my link without text. it doesn't work, null in a first parameter its not allowed. image is to short as normal. how can i use html.actionlink without text but with image??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个解决方案。
从本质上讲,ActionLink 用于文本链接,没有对应的图像链接,但您可以使用 Url.RouteUrl 来获取链接的地址,并将您喜欢的任何 HTML 代码放入锚点内(当然 W3C 允许)。
Here is a solution.
Essentially, ActionLink is for text links and there isn't an equivalent for images, but you can use Url.RouteUrl to get the address for the link and put any HTML code you like inside of the anchor (W3C permitting of course).
这种方法最简单(使用 Razor):
This way is easiest (using Razor):
基于之前的SO问题(已关闭),这里有一个解决方案:
可以在此处找到原始解决方案: 是否有用于图像链接的 ASP.NET MVC HtmlHelper?
based on a previous SO question (that was closed), here's a solution:
the orignal can be found here: Is there an ASP.NET MVC HtmlHelper for image links?
这是我的谦卑贡献,使用 Razor(作为示例)将 Font Awsome 字符用作图像:
两个引号之间的字符是 alt+255(按 ALT 键,然后在 num 上键入 255)键盘,然后松开 ALT 键)。
事实上,“”、“”和 string.Empty 都不能与 ActionLink 一起使用,但 alt-255 可以。这是一个非常古老的技巧(来自 DOS 时代),用于显示隐藏的空白字符。到目前为止,我还没有遇到这个技巧的任何问题。
Here is my humble contribution, using Razor (as an example) for when a Font Awsome character is used as an image:
The character in between the two quotes is alt+255 (hit the ALT key, then key-in 255 on the num keyboard, then release the ALT key).
Indeed, neither "" nor " " nor string.Empty work with ActionLink, but alt-255 does. This is a very old trick (from the DOS days) to display a hidden blank character. So far I have not encountered any problems with this trick.