码迷,mamicode.com
首页 > Web开发 > 详细

Ajax.ActionLink(),增加对img的支持

时间:2016-08-01 10:36:01      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

@Ajax.ActionLink("ActionLink", "Index", "Home", "https", "www", "title", new { id = 1, type = 1 }, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "detailsID", InsertionMode = InsertionMode.Replace }, new{ id = "testid"})

MVC.Ajax.ActionLink()只能显示文本内容在前端页面,不过很多时候 我们都使用图片作为超链接

public static IHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, string altText, string actionName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes = null)
        {
            var builder = new TagBuilder("img");
            builder.MergeAttribute("src", imageUrl);
            builder.MergeAttribute("alt", altText);
            builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            var link = helper.ActionLink("[replaceme]", actionName, routeValues, ajaxOptions).ToHtmlString();
            return MvcHtmlString.Create(link.Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing)));
        }
@Ajax.ImageActionLink(Url.Content("~/Content/Images/favorite.gif"),"收藏", "AddFavorite",null, new AjaxOptions { UpdateTargetId = "addfavorite" })

Ajax.ActionLink(),增加对img的支持

标签:

原文地址:http://www.cnblogs.com/cai6339988/p/5724669.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!