Call Action via javascript

0

Good afternoon, I need help with a simple problem, but it's knocking me down.

I need to call a controller method and pass two parameters to it, I did something, but it's not working, does anyone know where I'm going wrong?

View

<input type="submit" value="Confirmar" name="DuploSIM" id="btnDS" class="btn btn-info btn-lg" />

Script

$('#btnDS').click(function () {
    var pass = $('#txtDuplo').val()
    var action = $('#btnClick').val()
    if (pass == null) {
        alert('O campo de senha deve ser preenchido.');
        return false;
    }
    if (pass.length != 8) {
        alert('O campo de senha deve conter 8 caracteres.');
        return false;
    }

    var resultado = { "pass": pass, "index": action };

    $.ajax({
        url: '@Url.Action("DuploSIM", "Renegociacao")',
        datatype: 'json',
        contentType: "application/json; charset=utf-8",
        type: "POST",
        data: JSON.stringify(resultado), 
        success: function (data) {
            alert('sucesso!!');
        },
        error: function (error) {
            loading(0, "");
        }
    });
    return false;
});

Controller

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult DuploSIM(string pass, string index)
{
    FormularioModel model = (FormularioModel)Session["modelReg"];

    try
    {

        if (string.IsNullOrEmpty(pass))
            return RedirectToAction("Index", "Renegociacao", new { idOperacao = model.idOperacao, msg = "É necessário preencher o campo senha antes de confirmar." });
        else
            if (ValidarSenhaSuperior(Convert.ToInt32(pass), Convert.ToInt32(model.funcional)))
            {
                return RedirectToAction(index, "Renegociacao", new { model = model });                        
            }
            else
                return RedirectToAction("Index", "Renegociacao", new { idOperacao = model.idOperacao, msg = "Senha não confere com o superior." });
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
}
    
asked by anonymous 13.03.2017 / 19:33

1 answer

1

Try this:

$('#btnDS').click(function () {
var pass = $('#txtDuplo').val()
var action = $('#btnClick').val()
if (pass == null) {
    alert('O campo de senha deve ser preenchido.');
    return false;
}
if (pass.length != 8) {
    alert('O campo de senha deve conter 8 caracteres.');
    return false;
}

var resultado = { "pass": pass, "index": action };

$.ajax({
    url: '/DuploSIM/Renegociacao',
    datatype: 'json',
    contentType: "application/json; charset=utf-8",
    type: "POST",
    data: JSON.stringify(resultado), 
    success: function (data) {
        alert('sucesso!!');
    },
    error: function (error) {
        loading(0, "");
    }
});
return false;
});
    
14.03.2017 / 12:43