Invio dati json con ajax a controller restituisce sempre NULL

di
Anonimizzato29444
il
17 risposte

17 Risposte - Pagina 2

  • Re: Invio dati json con ajax a controller restituisce sempre NULL

    Prova a togliere dalla richiesta ajax anche

    contentType: "application/json",
  • Re: Invio dati json con ajax a controller restituisce sempre NULL

    Ora funziona!!!!!
    grazie a tutti!
  • Re: Invio dati json con ajax a controller restituisce sempre NULL

    Alleluia!


    In teoria dovrebbe funzionarti anche così ( e sul mio pc funziona)
    ( forse tu hai qualche problema con il provider json per il modelbinding)
    ... ma accontentiamoci
    
                $(document).ready(function () {
    
    
                    $('#submit').click(function () {
                        var data = { "data": { username: "test", password: "pwd" } };
                    
                        //debugger;
                        $.ajax({
                            url: "@Url.Action("/myAction")",
                            type: "POST",
                            data: JSON.stringify(data),
                            contentType: "application/json",
                            dataType: "json",
                            success: function (data) {
                                //debugger;
                                alert(data);
                            },
                            error: function (err) {
                                debugger;
                                alert('errore:' + err);
                            }
                        }
                        );
                    });
                });
    
Devi accedere o registrarti per scrivere nel forum
17 risposte