Get ID inserted by Ajax

1

I have a function that includes a register, and when adding I call another function, in this other function I need to pass the last included ID, how can I do this?

function SalvarHorario() {


    //NomeHorario
    var nome = $("#Nome").val();

    var token = $('input[name="__RequestVerificationToken"]').val();
    var tokenadr = $('form[action="/Horario/Create"] input[name="__RequestVerificationToken"]').val();
    var headers = {};
    var headersadr = {};
    headers['__RequestVerificationToken'] = token;
    headersadr['__RequestVerificationToken'] = tokenadr;

    //Gravar
    var url = "/Horario/Create";

    $.ajax({
        url: url
        , type: "POST"
        , datatype: "json"
        , headers: headersadr
        , data: { Id: 0, Nome: nome, __RequestVerificationToken: token }
        , success: function (data) {
            //if (data.Resultado > 0) {
            ListarItens(data.Resultado);
            //}
        }
    });
}

This function works, but for the ListItem function I need to pass the idHorario, which has just been included, in every way I try, it goes null. Here's how List Listing works.

function ListarItens(idHorario) {

    var url = "/HorarioItem/Create";

    $.ajax({
        url: url
        , type: "GET"
        , data: { id: idHorario }
        , datatype: "html"
        , success: function (data) {
            var divItens = $("#divItens");
            divItens.empty();
            divItens.show();
            divItens.html(data);
        }
    });

}

I tried idHarary = date, idHarary = data.Id, idHarary = data.Result. By including already I need to pass this id to the other function. I'm working with MVC Core. Thank you.

    
asked by anonymous 28.05.2018 / 13:53

0 answers