javascript result for method in parameterized controller

2

I'm trying to send the result of a WebAPI that is consumed via javascript on the page to a method in the controller that will do a persistence with that data

this is javascript

$('#CodigoCep').blur(function() {
        var cep = $('#CodigoCep').val();
        
        $.getJSON("http://localhost:13943/cep/" + cep,
                function (data) {
                    $('#Logradouro').val(data.logradouro);
                    $('#Bairro').val(data.bairro);
                    $('#Cidade').val(data.cidade);
                    $('#Estado').val(data.estado);
                })
            .fail(function () {
                $('#Logradouro').val('');
                $('#Bairro').val('');
                $('#Cidade').val('');
                $('#Estado').val('');
            });
    });

This is the method in the controller:

[HttpPost]
private void CadastraCep(string modelo)
{            
   ... persistir modelo
}

How to get the result of the first ajax and send to this method?

    
asked by anonymous 26.05.2016 / 04:50

1 answer

0

You will create a new call by passing the data See the example below.

$.ajax({
  type: "POST",
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

In this case, you will preferably need this data to be a JSON object, and in the controller you will manipulate this Json object.

Here are some examples. link

    
22.03.2017 / 19:05