我认为更好的方法是为你的助手文件夹中的这些重载创建一个扩展方法,然后在你的视图中使用它。只是取决于个人喜好
public static class ImageActionLinkHelper
{
public static string ImageActionLink(this HtmlHelper helper, string ImageUrl, string altText, string actionName, object routeValues)
{
var builder = new TagBuilder("img");
builder.MergeAttribute("src", ImageUrl);
builder.MergeAttribute("alt", altText);
builder.MergeAttribute("title", altText);
var link = helper.ActionLink("[replaceme]", actionName, routeValues, new { @class = "imgicon" });
return link.ToString().Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing));
}
public static string ImageActionLink(this HtmlHelper helper, string ImageUrl, string altText, string actionName, object routeValues, string Id, string display)
{
var builder = new TagBuilder("img");
builder.MergeAttribute("src", ImageUrl);
builder.MergeAttribute("alt", altText);
builder.MergeAttribute("title", altText);
var link = helper.ActionLink("[replaceme]", actionName, routeValues, new { @class = "imgicon", id = Id, style = display });
return link.ToString().Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing));
}
使用它SO建议手动创建``元素
@Html.ImageActionLink("../../Content/images/edit.png", "Edit", "Edit", new { id = item.UserId})
最相关的问题,但这里是一个使用CSS隐藏文字提问:HTTP:// stackoverflow.com/q/596444/342156 –
你试过空串吗? @ Html.ActionLink(“”,“PopupReferenceEdit”,新... – killebytes