如何在选中时突出显示Ajax.ActionLink

时间:2012-01-30 16:33:55

标签: ajax asp.net-mvc

那么当客户端点击Ajax.ActionLink时,我如何突出显示我在CSS中有一个适用于@ Html.ActionLink的类但是

 @Ajax.ActionLink("select", "Index", "Certificacion",
                      new { id = item.CertificacionId },
                      new AjaxOptions
                      {
                          HttpMethod = "GET",
                          UpdateTargetId = "linkEdit",
                          InsertionMode = InsertionMode.Replace
                      },
         new { @class = "selectedRow" })|

那么怎样才能使客户知道所选择的

1 个答案:

答案 0 :(得分:3)

这可以通过JavaScript完成。这是一个使用jQuery的例子:

@Ajax.ActionLink("select", "Index", "Certificacion", 
                      new { id = item.CertificacionId }, 
                      new AjaxOptions 
                      { 
                          HttpMethod = "GET", 
                          UpdateTargetId = "linkEdit", 
                          InsertionMode = InsertionMode.Replace 
                      }, 
         new { @class = "selectedRow", id = "YourActionLink" })
@* Notice the added html attribute property *@

然后你的jQuery代码可能是这样的:

$(document).ready(function() {
    $('#YourActionLink').click(function()
        {
            $(this).addClass('YourSelectedItemClass');
        });
});

然后只是一些非常简化的CSS来完成这个例子:

.YourSelectedItemClass
{
    background-color: yellow;
}


jQuery工作示例

请参阅此working jQuery jsFiddle以证明jQuery是正确的。

相关问题