没有文本的Ajax.ActionLink(显示为只有一个图标的jQuery按钮)

没有文本的Ajax.ActionLink(显示为只有一个图标的jQuery按钮),jquery,asp.net-mvc,Jquery,Asp.net Mvc,我使用以下ajax ActionLink方法 @Ajax.ActionLink(" ", "RemovePerson", "General", new { PersonId = item.PersonId }, new AjaxOptions { Confirm = "Are you sure?", HttpMethod = "Delete", OnSuccess = "JsonDelete_OnSuccess" }, new { @class = "PersonRemove" }) $()

我使用以下ajax ActionLink方法

@Ajax.ActionLink(" ", "RemovePerson", "General", new { PersonId = item.PersonId }, new AjaxOptions { Confirm = "Are you sure?", HttpMethod = "Delete", OnSuccess = "JsonDelete_OnSuccess" }, new { @class = "PersonRemove" }) 

$().ready(function () {
    $(".PersonRemove").button({ icons: { primary: "ui-icon-trash"} });
})
结果如下:

如您所见,linkText参数为“”。我不希望我的按钮中有任何文本。只有一个图标。我没有找到任何其他的解决方案来提供没有文本的ajax ActionLink,但我对它不是很满意。我需要一些建议

有没有比第一个参数为“”的ActionLink更好的解决方案

我更喜欢这样的:

@Ajax.ActionLink(null, ....
但它不起作用。我收到错误“值不能为null或空”


谢谢。

的确,这很烦人。您可以编写自定义MyActionLink帮助程序:

public static IHtmlString MyActionLink(
    this AjaxHelper ajaxHelper, 
    string actionName, 
    string controllerName, 
    object routeValues, 
    AjaxOptions ajaxOptions, 
    object htmlAttributes
)
{
    return ajaxHelper.ActionLink(
        " ", 
        actionName, 
        controllerName, 
        routeValues, 
        ajaxOptions, 
        htmlAttributes
    );
}
然后:

@Ajax.MyActionLink(
    "RemovePerson", 
    "General", 
    new { 
        PersonId = item.PersonId 
    }, 
    new AjaxOptions { 
        Confirm = "Are you sure?", 
        HttpMethod = "Delete", 
        OnSuccess = "JsonDelete_OnSuccess" 
    }, 
    new { @class = "PersonRemove" }
)

action链接确实不允许将空字符串作为文本参数

一个很快的解决办法是在.button()调用之后添加以下javascript:


我更喜欢定义文本缩进等于-9999px的样式。这将隐藏文本。例如:

a.settingsButton 
{
    position:absolute;
    width:95px;
    height:95px;
    background:url(images/settingsButton.png) 0 0 no-repeat;
    text-decoration: none; 
    top:20px;
    left:125px;
    text-indent: -9999px; /* hides the link text */
}

是的,我可以。所以你同意我的观点,使用Ajax.ActionLink(“,…不是很优雅吗?我一直在寻找一种很好的方法。谢谢。谢谢你,Darin。所以事实上,在这个解决方案中,我们只是“移动”了自定义帮助器中的“”问题,但是仍然存在…隐藏。所以这是一个可接受的解决方案?@Bronzato,是的,对我来说这是一个可接受的解决方案。我们不再需要重复
“”
在我们希望生成链接的每个视图中。我们已将其外部化为可重用的帮助程序。感谢您的解决方案。这似乎也是一个很好的替代方案,但我无法使用它。我尝试过,我的jQuery按钮除了图标外,其他都丢失了!但我尝试过使用empty(),这次它可以工作。无论如何,谢谢。
a.settingsButton 
{
    position:absolute;
    width:95px;
    height:95px;
    background:url(images/settingsButton.png) 0 0 no-repeat;
    text-decoration: none; 
    top:20px;
    left:125px;
    text-indent: -9999px; /* hides the link text */
}