ASP.Net MVC5: Get Base URL in JavaScript

* Get base url

    <script type="text/javascript">
        var baseUrl = '@Url.Content("~")';
    </script>

* Use it in ajax, for example:

$(document).ready(
    function () {
        var vm = new ViewModel();
 
        $.ajax({
            url: baseUrl + 'api/menu/',
This entry was posted in asp.net, JavaScript and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.