如何在 asp mvc 2 中使用 css 添加图像?
我想使用 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.)
Expected outcome:
Any help is appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下使用 ActionLink 是不必要的,只需使用常规图像或 div
您可以将其添加到样式中,使其更像链接:
最后,当您选择它来添加单击处理程序时,如果您使用
$ ('a.get-reservation')
更改为$('div.get-reservation')
或简单地$('.get-reservation')
Using ActionLink in this case is unnecessary, just use regular image or div
You can add this to the style, to make it more like a link:
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')
我认为你应该这样做:
请注意,第一个参数是要显示的文本,这就是为什么你之前在屏幕上有一个“#”。第三个参数是 null RouteValues,第四个参数是附加的 html 属性。
这里有方法定义: http://msdn.microsoft.com/en- us/library/dd492124.aspx
希望对您有所帮助。干杯
I think you should do this:
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