ASP.NET MVC Ajax.ActionLink与图片 [英] ASP.NET MVC Ajax.ActionLink with Image

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

问题描述

反正是有有一个形象的行为作为Ajax ActionLink的?我只能把它用文字工作。感谢您的帮助!

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!

推荐答案

从斯蒂芬Walthe,从他的<一个href="http://www.asp.net/mvc/tutorials/older-versions/contact-manager/iteration-1-create-the-application-cs">Contact马槽项目

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屋!

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