2
If anyone can help me:
I’m doing an ASP.NET MVC system of academic control. At the time of enrollment, I wanted to put a blank field to enter the CPF, and other fields as the name, but only for presentation, and get the id to effect the registration.
I would do a search for the number on Controller and returns the student or a message saying that the student was not found. I have tried some functions but without success.
I put more or less functions of this type:
<script>
$('#cpf').change(function (e) {
e.preventDefault();
$("#nome").val('');
$("#idAluno").val('');
var cpf = $('#cpf').val();
$.getJSON("/Cursos/RetornaAluno" + cpf + "&formato=json", {}, function (data) {
if (data.aluno_txt != null) {
$("#nome").val(data.nome);
$("#idAluno").val(data.idAluno);
}
else {
alert("Aluno não encontrado");
$("#cpf").focus();
}
});
});
</script>
And I created a ActionResult
in the Controller that returns the object. I had never used jQuery so I don’t know how to do.
public ActionResult RetornaAluno(string cpf)
{
var aluno = from a in db.Alunos select a;
aluno = aluno.Where(a => a.cpfAluno == cpf);
return Json(aluno, JsonRequestBehavior.AllowGet);
}
You can edit your question and put what you have tried to do?
– Leonel Sanches da Silva
Okay, now I need the code from Controller also.
– Leonel Sanches da Silva