Ajax.ActionLink与图像 [英] Ajax.ActionLink with image

查看:245
本文介绍了Ajax.ActionLink与图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要创建一个图像按钮调用的操作方法,您可以使用建筑像

To create an image button that calls an action method you can use construction like that

<a href="@Url.Action("SomeAction")" ><img src="image.jpg"/> </a>

但是,如果我真的需要一个Ajax调用? 我可以使用jQuery,并绑定一个JavaScript事件的按钮,但我不知道是否有,甚至更简单的方法,没有污染的标记与脚本?

But what if I actually need an ajax call? I can use jQuery, and bind a javascript event to the button, but I wonder if there is even an easier way, without polluting markup with scripts?

推荐答案

尝试

@Ajax.ActionLink("LinkText", "ActionName", "ControllerName", your route values or null, new AjaxOptions { UpdateTargetId="Div1"}, new { @class = "MyCssClass" })

CSS 文件

.MyCssClass
{
  background-image:url(image.jpg);
}

修改

@Ajax.ActionLink("LinkText", "ActionName", "ControllerName", your route values or null, new AjaxOptions { UpdateTargetId = "Div1" }, new { style = "background-image:url(image.jpg)" })

注意

您应该WIRTE图像(相对路径)的完整路径。

you should wirte the full path of your image(relative path).

这篇关于Ajax.ActionLink与图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆