【问题标题】:create ajax actionlink with html elements in the link text在链接文本中使用 html 元素创建 ajax actionlink
【发布时间】:2012-08-14 02:03:13
【问题描述】:

我想将链接转换为 ajax 操作链接。我不知道如何在链接文本中显示 html 元素?

这里是原文链接:

<a href="#onpageanchor" id="myId" class="myClass" title="My Title."><i class="icon"></i>Click Me</a>

这里是 ajax 操作链接:

@Ajax.ActionLink("<i class='icon'></i>Click Me", "MyActionMethod", new { id = "testId" },
                        new AjaxOptions
                        {
                            UpdateTargetId = "mytargetid"
                        }, new
                        {
                            id = "myId",
                            @class = "myClass",
                            title="My Title."
                        })

呈现的链接文本是实际的字符串:"&lt;i class='icon'&gt;&lt;/i&gt;Click Me&lt;/a&gt;"

【问题讨论】:

标签: asp.net-mvc asp.net-mvc-3 razor asp.net-ajax


【解决方案1】:
@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" })

【讨论】:

    【解决方案2】:

    我创建了 Ajax.ActionLink 来显示图像而不是链接文本

        @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" })
    

    申请班级

     .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;
    }
    

    希望这段代码对你有用。

    谢谢。

    【讨论】:

      【解决方案3】:

      晚了一年多,但这是我用的。希望它可以帮助别人。

      @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" })
      

      然后是助手...

          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));
          }  
      

      【讨论】:

      • 正是我想要的;太棒了!
      猜你喜欢
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      相关资源
      最近更新 更多