2014-02-16 27 views

回答

1

您可以使用Url.Action幫手:

<script type="text/javascript"> 
    var url = '@Url.Action("Foo", "Bar")'; 
    someJavascriptfunction(url); 
</script> 

或者,你可以直接從DOM中提取此信息。讓我們假設你在你的DOM錨:

@Html.ActionLink("click me", "Foo", "Bar") 

要AJAXify在你的JavaScript文件:

$('a').click(function() { 
    $.ajax({ 
     url: this.href, 
     type: 'GET', 
     cache: false, 
     success: function(result) { 
      // Do something with the result of the AJAX call 
     } 
    }); 
    return false; 
}); 
相關問題