create ajax actionlink with html elements in the link text

后端 未结 3 1600
小鲜肉
小鲜肉 2020-12-16 02:33

I would like to convert a link to an ajax action link. I can\'t figure out how to display html elements within the link text?

Here is the original link:



        
相关标签:
3条回答
  • 2020-12-16 03:20

    over a year late and everything but this is what I use. Hope it helps someone else.

    @Ajax.RawActionLink(string.Format("<i class='icon'></i>Click Me"), "ActionResultName", null, new { item.Variable}, new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "taget-div", LoadingElementId = "target-div" }, new { @class = "class" })
    

    Then the helper...

        public static MvcHtmlString RawActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes)
        {
            var repID = Guid.NewGuid().ToString();
            var lnk = ajaxHelper.ActionLink(repID, actionName, controllerName, routeValues, ajaxOptions, htmlAttributes);
            return MvcHtmlString.Create(lnk.ToString().Replace(repID, linkText));
        }  
    
    0 讨论(0)
  • 2020-12-16 03:35

    I have created Ajax.ActionLink to display image instead of link text

        @Ajax.ActionLink(".", "Delete_Share_Permission", "Share", new { delwhich = "one", delid = @UserSharingDetails.PK_User_Sharing_Id }, new AjaxOptions { UpdateTargetId = "sharelist", InsertionMode = InsertionMode.Replace, OnBegin = "return confirmdeleteone();" }, new { @class = "deleteButton", @id = "fna" })
    

    Applying class

     .deleteButton {        
        background-image: url("/images/DeleteData.png");
        position: absolute;
        right: 6px;
        background-repeat: no-repeat;
        border: none;
        background-position: 50% 50%;
        margin-left: 10px;
        background-color: transparent;
        width: 13px;
        color: #ffffff !important;
        display: block;
        top: 5px;
    }
    

    I hope this code is useful to you.

    Thank you.

    0 讨论(0)
  • 2020-12-16 03:38
    @Ajax.ActionLink(" Name", "AjaxGetAllUsers", "Admin", new { sortBy = ViewBag.SortByName, search = Request.QueryString["search"] }, new AjaxOptions() { UpdateTargetId = "userlist", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }, new { @class = "fa fa-sort" })
    
    0 讨论(0)
提交回复
热议问题