在webgrid中添加链接按钮

时间:2013-02-11 07:37:55

标签: asp.net-mvc-4

我希望在mvc webgrid中添加一个linkbutton类型,它应该调用一个javascript方法。

我现在正在使用:

hiddenDiv.Column("",style: "col1",format: @<text>
<button class="edit-book display-mode" id="@item.FacilityID">
    Select</button>
</text>)

调用:

$('.edit-book').on('click', function () {
        $('#hiddendiv2').show();
        $('#facilitygrid').hide();
        var bookId = $(this).prop('id');
        alert(bookId);
    });

但我没有按钮,而是想放一个链接按钮。

1 个答案:

答案 0 :(得分:1)

由于我们在mvc中没有链接按钮,您可以通过覆盖Action Link的默认行为来使用@Html.ActionLink

hiddenDiv.Column("",style: "col1",format: @<text>
    @Html.ActionLink("Home","Index",null, new { @class="ImgAddition", @onclick="SomeScript(this);"})
</text>)

为了显示图像而不是链接,您应该添加以下css

.ImgAddition{
     background: url(../Images/image.gif) no-repeat top left;/* add image*/
     display: block;
     width: 100px;
     height: 100px;
     text-indent: -9999px; /* hides the link text */

}

最后你的剧本:

$('.ImgAddition').on('click', function (e) {
        e.preventDefault();
        $('#hiddendiv2').show();
        $('#facilitygrid').hide();
        var bookId = $(this).prop('id');
        alert(bookId);
    });

希望它有所帮助。

相关问题