带有图像的 ASP.NET MVC Ajax.ActionLink [英] ASP.NET MVC Ajax.ActionLink with Image
本文介绍了带有图像的 ASP.NET MVC Ajax.ActionLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
反正有图像作为ajax动作链接吗?我只能使用文本让它工作.感谢您的帮助!
is there anyway to have an image act as an ajax actionlink? I can only get it to work using text. Thanks for your help!
推荐答案
来自 Stephen Walthe,来自他的 联系管理器项目
From Stephen Walthe, from his Contact manger project
public static class ImageActionLinkHelper
{
public static string ImageActionLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, object routeValues, AjaxOptions ajaxOptions)
{
var builder = new TagBuilder("img");
builder.MergeAttribute("src", imageUrl);
builder.MergeAttribute("alt", altText);
var link = helper.ActionLink("[replaceme]", actionName, routeValues, ajaxOptions);
return link.Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing));
}
}
您现在可以输入您的 aspx 文件:
You can now type in your aspx file :
<%= Ajax.ImageActionLink("../../Content/Delete.png", "Delete", "Delete", new { id = item.Id }, new AjaxOptions { Confirm = "Delete contact?", HttpMethod = "Delete", UpdateTargetId = "divContactList" })%>
这篇关于带有图像的 ASP.NET MVC Ajax.ActionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文