Asp.net 如何在@Html.actionlink中用字形图标替换actionlink文本?
我想用Asp.net 如何在@Html.actionlink中用字形图标替换actionlink文本?,asp.net,asp.net-mvc,twitter-bootstrap,twitter-bootstrap-3,glyphicons,Asp.net,Asp.net Mvc,Twitter Bootstrap,Twitter Bootstrap 3,Glyphicons,我想用glyphion垃圾桶替换X 我正在使用X作为链接文本。用于删除项目。如何替换为图标 这是我的密码 @Html.ActionLink( "X", "Delete", "Grocery", new { GroceryUsageID = item.GroceryUsageID, GroceryId = item.Grocery
glyphion垃圾桶替换X
我正在使用X
作为链接文本。用于删除项目。如何替换为图标
这是我的密码
@Html.ActionLink(
"X",
"Delete",
"Grocery",
new { GroceryUsageID = item.GroceryUsageID, GroceryId = item.GroceryID },
new { @onclick = "return confirm('Are you sure you want to delete this Grocery');"})
试试这个。抄袭自;)
您可以像下面这样做。只需在htmlAttributes
参数中添加@class=“glyphicon glyphicon trash”
,并用空格替换X
@Html.ActionLink(
" ",
"Delete",
"Grocery",
new { GroceryUsageID = item.GroceryUsageID, GroceryId = item.GroceryID },
new { @onclick = "return confirm('Are you sure you want to delete this Grocery');",
@class = "glyphicon glyphicon-trash" })
这是我的实现,便于重用
助手方法扩展类
namespace Extensions {
using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
public static class HtmlExtensions {
public static MvcHtmlString FALink(this HtmlHelper htmlHelper, string action, string controller, string link_text, string fa_class, string btn_css_classes = "", string button_id = "", object route_values = null) {
// declare the span
TagBuilder span = new TagBuilder("span");
span.AddCssClass($"fa fa-{fa_class}");
span.MergeAttribute("aria-hidden", "true");
// declare the anchor tag
TagBuilder anchor = new TagBuilder("a");
// Add the href attribute to the <a> element
if (string.IsNullOrEmpty(controller) || string.IsNullOrEmpty(action))
anchor.MergeAttribute("href", "#");
else
anchor.MergeAttribute("href", new UrlHelper(HttpContext.Current.Request.RequestContext).Action(action, controller, route_values));
// Add the <span> element and the text to the <a> element
anchor.InnerHtml = $"{span} {link_text}";
anchor.AddCssClass(btn_css_classes);
anchor.GenerateId(button_id);
// Create the helper
return MvcHtmlString.Create(anchor.ToString(TagRenderMode.Normal));
}
}
}
基本链接类型按钮:
@Html.FALink("ActionNameHere", "ControllerNameHere", "Back to List, "th-list")
基本链接类型按钮,使用引导为文本着色
@Html.FALink("ActionNameHere", "ControllerNameHere", "Back to List", "th-list, "btn-info")
- 当我使用Font Awesome时,您可以轻松地用引导glyphicon类替换fa以使用引导glyphicon
- 如果没有传入任何控制器或操作,它将使用#作为链接位置,这样就可以很好地进行下拉交互
您能更详细地描述一下您的问题吗?何时要替换文本?如果您想替换,那么您是否尝试过在客户端使用JQuery?我需要将十字标记替换为垃圾glypicon可能的重复项我不相信class=“btn btn warning”是必要的,因为glypicon加号用于显示+号。
@Html.FALink("ActionNameHere", "ControllerNameHere", "Back to List, "th-list")
@Html.FALink("ActionNameHere", "ControllerNameHere", "Back to List", "th-list, "btn-info")