ASP.Net MVC : ActionLink with bootstrap icon

How many times you wanted to add an icon to your action link?!. using Html.ActionLink method is not possible to add icon as it renders the link with just HtmlAttribute you provide.
ex :
@Html.ActionLink("My Link","actionName","controllerName",new {id = Model.Id},
new {style="margin:10px", @class="btn btn-info"});
this will be rendered as shown in 
 if I want to add icon using bootstrap css classes, I can not use HtmlHelper methods and have to use plain html tags like this
<a href="url-here" class="btn btn-info" style="margin:10px;">
        <i class="glyphicon glyphicon-pencil"></i>
        <span>My Link</span>
    </a>
this will be rendered  as
so to simplify my .cshtml file and make it easy for developers to add icon to their action links, I have created an extension method IconActionLink that will replace the previous html sinppet and give the same result.
@Html.IconActionLink("My Link", "actionName", "controllerName", null, 
new { @class = "btn btn-info" }, "glyphicon glyphicon-pencil")
the big difference and most important is the icon css class parameter .

Nuget Package : https://www.nuget.org/packages/Mirosoft.Utilities.Mvc
Source code : https://github.com/miroprocessor/Mirosoft.Utilities.Mvc

Comments

Post a Comment

Popular posts from this blog

ASP.Net MVC : Conditional Validation using ValidationAttribute

Android : How to change progress bar color at runtime programmatically?