0
Hello, I’m beginner in programming, and I’m trying to pass data via Ajax to my Controller, to be honest I’m just studying so I don’t even know for sure understand the advantages of Jquery for this...
Following some examples, I did it as follows:
var nome = document.getElementById("Nome").value;
var sobrenome = document.getElementById("Sobrenome").value;
var email = document.getElementById("Email").value;
var senha = document.getElementById("Senha").value;
if (nome == null || nome == "") {
return alert("FALTA INFORMAÇÃO");
}
if (sobrenome == null || sobrenome == "") {
return alert("FALTA INFORMAÇÃO");
}
if (email == null || email == "") {
return alert("FALTA INFORMAÇÃO");
}
if (senha == null || senha == "") {
return alert("FALTA INFORMAÇÃO");
}
$.ajax({
type: 'POST',
url: '../VerificaDuplicidadeCadastro/Home=email?' + email,
//data: email,
Well, I left commented the 'date' because in the examples everyone uses it, but I honestly do not understand how it works, so I tried to pass the email through the same URL, but in my controller I am receiving the null value.
Follow the controller:
public IActionResult VerificaDuplicidadeCadastro(string email)
{
var con = new Conexao();
con.OpenConnection();
con.CloseConnection();
return Json(true);
}
How can I do it properly?
Thank you.
The
data
you can send in two ways:data: "email="+email
ordata: {email: email}
.– Sam
@Sam, thanks for the answer, but both ways the value received in Controller continues to be received as null.
– L Thomaz