0

I want to pass the url generated via Html.ActionLink to a javascript function argument. So, how could I do this?

Thanks in advance,

1 Answer 1

1

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;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.