Ajax url changes on the server - MVC

0

Is it wrong to declare urls in ajax in this way?

$.ajax
        ({
            url: '/SFI_IncentivoDet/buscarIncentivosSinDetalles',
            type: 'post'
        });

I am working with the functions in separate files, in some cases I have to put ../ before the controller (apparently if I call the function from a different view to the destination controller)

The problem is that when I pass the application to the server or to another computer I have to modify the url parameter in some cases. Thank you very much!

    
asked by Valentina Oppen 04.08.2017 в 07:27
source

1 answer

3

If you are using ASP MVC it would be convenient to generate the links using the @Url.Action . When you pass the controller and the method you want to call, it generates the addresses dynamically. Getting this you do not have to change the URL manually every time you change server.

$.ajax
({
    url: '@Url.Action("SFI_IncentivoDet","buscarIncentivosSinDetalles")',
    type: 'post'
});
    
answered by 04.08.2017 в 09:36