ajax actionlink和href undefined

时间:2014-02-06 23:00:22

标签: ajax asp.net-mvc-4 actionlink

检查以下代码:它工作正常。

@Html.SideMenuActionLink
    (
     "<i class=\"icon-windows\"></i>" + item.SourceConnectorsName,  
     new { ConnectorID = item.SourceConnectorsId, Action = "Main",
     controller = "Configuration" },                               
     new { @class = "menuLink" }                                     
     )    


<script type="text/javascript">
$(function () {
    $('.menuLink').click(function () {
        history.pushState(null, "Configuration", this.href);
        $('#configurationpanel').load(this.href);
        return false;
    });
});

现在,我正在(几乎)使用@ Ajax.ActionLink:

@Ajax.ActionLink("Connection", "Connection", 
     "Configuration", 
      new { connectorID = Model.SourceConnectorsId }, 
       new AjaxOptions { UpdateTargetId = "result", OnSuccess = "pushState" })

<script type="text/javascript">
function pushState() 
{
    alert this.href;
}
</script> 

问题:this.href未定义。我无法找到原因。

1 个答案:

答案 0 :(得分:0)

试试这个:

<script>
function pushState(ev) 
{
    var element = $(ev.target);
    alert(element.attr("href"));
}
</script>