I want to pass the url generated via Html.ActionLink to a javascript function argument. So, how could I do this?
Thanks in advance,
You could use the Url.Action helper:
<script type="text/javascript">
var url = '@Url.Action("Foo", "Bar")';
someJavascriptfunction(url);
</script>
Alternatively, you could extract this information directly from the DOM. Let's suppose that you have an anchor in your DOM:
@Html.ActionLink("click me", "Foo", "Bar")
that you want to AJAXify in your javascript file:
$('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;
});