how to generate Html.ActionLink with icon

后端 未结 6 2109
故里飘歌
故里飘歌 2020-12-14 15:30

I\'m starting to learn ASP.NET MVC, and have a problem, how generate code with Html.ActionLink like this:



        
相关标签:
6条回答
  • 2020-12-14 15:30

    This example may help you.

    @Html.ActionLink(" ", "Controller", new { id = item.Id }, new { @class = "btn
                     btn-success btn-circle fa fa-plus-circle", title = "Confirm" })
    

    this way you will have an icon without the text.

    0 讨论(0)
  • 2020-12-14 15:42

    Html.ActionLink() only supports plain-text links.

    You should use <a href="@Url.Action(...)"> for more-complex links.

    0 讨论(0)
  • 2020-12-14 15:42

    I wanted to add to SLaks answer.

    Using <a href="@Url.Action(...)"> with what user2567619 wanted.

    <a href="@Url.Action("Create", "Home")" class="btn btn-primary">
        <i class="icon-pencil icon-white"></i>
        <span>
            <strong>Create</strong>
        </span>            
    </a>
    

    I think it's worth mentioning that @Url.Action can take it's parameters like this:

    @Url.Action(string actionName, string controllerName) 
    

    Whereas @Html.ActionLink can take it's parameters like this:

    @Html.ActionLink(string linkText, string actionName, string controllerName) 
    

    It may be pretty obvious, but I thought it was worth noting.

    Edit

    As Peck_conyon noted, for both @Url.Action and @Html.ActionLink, these are just one of the ten different overload methods.
    For documentation on UrlHelper.Action, look here.
    For documentation on LinkEtensions.ActionLink, look here.

    0 讨论(0)
  • 2020-12-14 15:44

    If it's in the Layout page, you can use this, I think it may help:

        <li>@Html.ActionLink(" Login", "Index", new { Controller = "Login", Area = "Security" }, new { @class = "glyphicon glyphicon-log-in" })</li>

    or like this for a action_link:

        <p>
        @Html.ActionLink(" Create New", "Add", "Event", FormMethod.Post, new { @class = "glyphicon glyphicon-plus" })</p>

    Hope this helps.

    0 讨论(0)
  • 2020-12-14 15:47
    @Html.ActionLink("Edit","Edit","",new { @class= "btn btn-primary" })
    

    Result

    0 讨论(0)
  • 2020-12-14 15:54

    Simple as this:

    @Html.ActionLink("Title", "Action", null, new {@class="btn btn-info fa fa-pencil" })
    
    0 讨论(0)
提交回复
热议问题