For a start, Ajax.ActionLink does not support inserting anything other than text, since the first argument is class System.String
, you can avoid this by using standard Bootstrap libraries like: GlyphIcons or FontAwesome.
then your panel code will look like this:
<ul class="nav nav-tabs" id="myTabs"> <li>@Ajax.ActionLink("1 класс", "Class1", "Work201615", new AjaxOptions { UpdateTargetId = "tabContent" }, new { @data_target = "#tabContent", @data_toggle = "tab", @class = "btn btn-default glyphicon glyphicon-edit" })</li> <li>@Ajax.ActionLink("2 класс", "Class2", "Work201615", new AjaxOptions { UpdateTargetId = "tabContent" }, new { @data_target = "#tabContent", @data_toggle = "tab" })</li> <li>@Ajax.ActionLink("3 класс", "Class3", "Work201615", new AjaxOptions { UpdateTargetId = "tabContent" }, new { @data_target = "#tabContent", @data_toggle = "tab" })</li> </ul>
Glyphs
Font-awesome
Well, here is a kosher solution:
Based on this discussion.
just change the css class to
.myLi { background-image:url(images/check.png); }
But if you need to use custom images:
There are two ways: Helpers
using System.Web; using System.Web.Mvc; using System.Web.Mvc.Ajax; public static class ImageActionLinkHelper { 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))); } }
and in the view it like this
@Ajax.ImageActionLink("../../Content/Delete.png", "Delete", "Delete", new { id = item.Id }, new AjaxOptions { Confirm = "Delete contact?", HttpMethod = "Delete", UpdateTargetId = "divContactList" })
Brazenly steal from here
or
<%= Ajax.ActionLink("[replacethis]", ...).Replace("[replacethis]", "<img src=\"/images/test.gif\" ... />" %>
What is not very beautiful, but quickly and simply. Square wheel bike
UPD: in the example, the wrong closing style tag in Layout.cshtml