Well, I'm new to asp.net
MVC
and I'm picking up some time already for a blessed View
. According to the help I had in this post #
Following the example I made my adaptations but now my View
is not rendering. Can someone give me strength?!
I made an Action GET returning View
and the page rendered, however, the action of my button does nothing, nor does it enter 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());
}
POST error
CourseList
My button after the click should also be disabled as per the code below. It's just that it's 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>