如何在 asp mvc 2 中使用 css 添加图像?

发布于 2024-11-05 01:12:04 字数 1105 浏览 0 评论 0原文

我想使用 css 类将可点击图像添加到 asp mvc 2 应用程序中的锚标记,并将 url 部分留空(因为我有 javascript 代码来根据给定锚标记的 id 加载弹出窗口)。

目前我的代码是:

<%= Html.ImageActionLink(null, null, "~/UI/Forms/Css/Images/get-reservation.png", null, new { @Id = "getReservation" }, new { @Class = "image" })%>

信息: 我添加了 Id,因为我使用 javascript 在单击 getReservation id 时加载弹出窗口。图像类只是添加填充。

当前的CSS代码:

.image
{
   padding-left: 10px;  
}

我想要什么:

从我的ImageActionLink助手

“~/UI/Forms/Css/Images/get-reservation.png”

中删除下面的路径并定义一个CSS类:

.get-reservation
{
background: url('images/get-reservation.png') no-repeat center;
height: 20px;
width:20px;
}

并执行类似的操作:

<%= Html.ActionLink("#", null, new { @Class = "get-reservation image" }, new { @Id = "getReservation" })%>

但是我得到了什么在浏览器中是这样的:(并且图像无法出现。)

在此处输入图像描述

预期结果:

在此处输入图像描述

感谢任何帮助。

谢谢

I want to add a clickable image using a css class to an anchor tag in an asp mvc 2 application and leave the url section empty(since I have javascript code to load a pop up based on the id given to the anchor tag).

Currently my code is :

<%= Html.ImageActionLink(null, null, "~/UI/Forms/Css/Images/get-reservation.png", null, new { @Id = "getReservation" }, new { @Class = "image" })%>

Info: I added the Id, since I am using javascript to load a pop up when the getReservation id is clicked. The image class just adds padding.

current css code :

.image
{
   padding-left: 10px;  
}

What I want:

To remove the path below from my ImageActionLink helper

"~/UI/Forms/Css/Images/get-reservation.png"

and define a css class:

.get-reservation
{
background: url('images/get-reservation.png') no-repeat center;
height: 20px;
width:20px;
}

and do something like this:

<%= Html.ActionLink("#", null, new { @Class = "get-reservation image" }, new { @Id = "getReservation" })%>

But what I get in the browser is something like this :(And the image fails to appear.)

enter image description here

Expected outcome:

enter image description here

Any help is appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔女人霸气范 2024-11-12 01:12:04

在这种情况下使用 ActionLink 是不必要的,只需使用常规图像或 div

<div class="get-reservation image" id="getReservation"></div>

您可以将其添加到样式中,使其更像链接:

border: none;
cursor: pointer; /* hand cursor */

最后,当您选择它来添加单击处理程序时,如果您使用 $ ('a.get-reservation') 更改为 $('div.get-reservation') 或简单地 $('.get-reservation')

Using ActionLink in this case is unnecessary, just use regular image or div

<div class="get-reservation image" id="getReservation"></div>

You can add this to the style, to make it more like a link:

border: none;
cursor: pointer; /* hand cursor */

Finally, when you select it to add the click handler, if you were using $('a.get-reservation') change to $('div.get-reservation') or simply $('.get-reservation')

起风了 2024-11-12 01:12:04

我认为你应该这样做:

<%= Html.ActionLink("", "#", null, new { @Id = "getReservation", @Class = "get-reservation image" })%>

请注意,第一个参数是要显示的文本,这就是为什么你之前在屏幕上有一个“#”。第三个参数是 null RouteValues,第四个参数是附加的 html 属性。

这里有方法定义: http://msdn.microsoft.com/en- us/library/dd492124.aspx

希望对您有所帮助。干杯

I think you should do this:

<%= Html.ActionLink("", "#", null, new { @Id = "getReservation", @Class = "get-reservation image" })%>

Note that the first parameter is the text to show, that's why you got a '#' on screen before. The third parameter is a null RouteValues, and the fourth is for the additional html attributes.

Here you have the method definition: http://msdn.microsoft.com/en-us/library/dd492124.aspx

Hope to have helped you. Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文