Url in jquery is being mounted wrong

Asked

Viewed 33 times

1

I have a View called Invoice, inside a controller named Order. If I take my jquery and leave url: '', it already mounts in the browser that:

locahost:porta/dominio/order/FaturarPara

I’ll go to jquery and do it url: /Order/GetDados, there in the Chrome Network I pick this up

locahost:porta/dominio/order/FaturarPara/Order/GetDados

Any configuration I make, I can’t mount the url correct. This is my jquery

$(document).ready(function () {
        $('#faturarParaDrop').change(function () {
            var $div = $('#modalPartial'); //exibir a modal
            var idcustomer = $(this).val(); //valor do id da dropdownlist
            $.ajax({
                url: '/Order/GetDados/' + idcustomer,
                type: 'GET',                
                success: function (dados) {
                    alert(JSON.stringify(dados));
                },
                error: function (erro) {
                }
            })
        });
    });

if I take this url and play in the browser, log in to Jsonresult

locahost:porta/dominio/Order/GetDados/1

How do I access my Jsonresult in the controller?

2 answers

1

I resolved so:

 url: '@Url.Action("GetDados/")' + idcustomer,

0

You have already solved your problem, but there is an important tip: when passing the parameter to the url called in ajax you can use the option data:

In your example it would look like this:

$(document).ready(function () {
    $('#faturarParaDrop').change(function () {
        var $div = $('#modalPartial'); //exibir a modal
        var idcustomer = $(this).val(); //valor do id da dropdownlist
        $.ajax({
            url: '@Url.Action("GetDados")',
            type: 'GET',
            data: idcustomer,
            success: function (dados) {
                alert(JSON.stringify(dados));
            },
            error: function (erro) {
            }
        })
    });
});

Read more in the api documentation: http://api.jquery.com/jquery.ajax/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.