1
Guys, I’m a beginner in asp.net
MVC
and I’m already picking up a certain amount of time for a blessed View
. According to the help I had in this post Button only works if you pass the ID in the URL in Asp.net MVC
Following the example I made my adaptations but now mine View
is not rendering. Someone can give me a strength?!
So I did an action GET returning to View
and the page rendered, however, the action of my button does nothing, nor enters the breakpoint
.
//GET
public ActionResult Inscricao()
{
return View(db.Cursos);
}
//POST
[HttpPost]
public ActionResult Inscricao(int inscricaoId)
{
using (var scope = new TransactionScope())
{
Aluno aluno = db.Alunos.FirstOrDefault();
if (aluno == null)
return View("Inscricao", db.Cursos.ToList());
var curso = db.Cursos.FirstOrDefault(c => c.Id == inscricaoId);
if (curso == null)
return View("Inscricao", db.Cursos.ToList());
var alunoCurso = new AlunoCurso
{
Aluno = aluno,
Curso = curso
};
db.AlunoCursos.Add(alunoCurso);
db.SaveChanges();
curso.Qtd_Vagas--;
db.Entry(curso).State = EntityState.Modified;
db.SaveChanges();
scope.Complete();
}
return View(db.Cursos.ToList());
}
Erro POST
List of Courses
My button after clicking should also be disabled as code below. Only it is not disabling.
<script>
$(document).ready(function() {
$("#inscricao").click(function() {
$.ajax({
type: "POST",
url: "Inscricao/",
data: {inscricaoId: $(this).data("inscricaoid")},
success: function() {
$(this).attr("disabled", "disabled");
}
});
});
});
</script>
Add the codes that calls the View
– Maicon Carraro
What appears in the browser log console when you click the button?
– Maicon Carraro
Appeared 3 errors GET @Maiconcarraro
– Novato
Shows which are
– Maicon Carraro