burnt1ce
burnt1ce

Reputation: 14897

How to get the URL of an action method in ASP.NET MVC using AJAX?

How can I make an AJAX call to retrieve the URL of controller's action method?

Upvotes: 0

Views: 161

Answers (2)

Lee Smith
Lee Smith

Reputation: 6747

Just inject the url into the javascript using the UrlHelper:

<script>

var url = '<%: Url.Action("ActionName") %>';

$.get(url);

</scrtip>

Upvotes: 1

Sruly
Sruly

Reputation: 10540

if you write the JS in your view you can write something like this.

var ajaxUrl = <%= Url.Action("NameOfAction") %>

this will put the url into your javascript code.

Upvotes: 2

Related Questions