2

In my MVC5 Project, I have used Jquery and to use Controller Actions, I used relative path. Here is a sample:-

 $("#divTree").jstree({
        'core': {
            'data': {
                "url": "/Customer/GetList",
                "dataType": "json"
            },
            "check_callback": true
        },
        "plugins": ["contextmenu", "dnd", "json_data"]
    });

I am also using relative paths in jquery.ajax() method. All relative paths are working in visual studio. But when I publish and host it in IIS, relative paths are not working.

In my asp.net web forms projects I am either using ReloveUrl() or ~.

How should i handle it in MVC 5 project.?

user1327064
  • 4,187
  • 5
  • 20
  • 30

2 Answers2

1

Try the following:

$("#divTree").jstree({
        'core': {
            'data': {
                "url": "~/Customer/GetList",
                "dataType": "json"
            },
            "check_callback": true
        },
        "plugins": ["contextmenu", "dnd", "json_data"]
    });
Ala
  • 1,505
  • 1
  • 20
  • 36
0

You should consider not hard coding the URLs in MVC apps and using the provided helpers instead. If the script is within a view, you can use @Url.Action() to generate the URL. If not, you can still pass it in as a param to the JS in some way or another.

$("#divTree").jstree({
    'core': {
        'data': {
            "url": '@Url.Action("Customer", "GetList")',
            "dataType": "json"
        },
        "check_callback": true
    },
    "plugins": ["contextmenu", "dnd", "json_data"]
});
Brad C
  • 2,868
  • 22
  • 33