4
Guys, I’m developing an application that manages Courses, and I’m trying to make a list where present on the screen the Courses, the Student Name and the countryside Approved, where it indicates whether it is approved or not, and on that screen I have to be able to mark the checkbox. The problem is that I’m not getting on the list of Student Name and I can’t even edit the field directly on that list Approved, because when I pass the mouse cursor it is locked and I can not check, the editing of this field on this screen is essential.
My Controller Course Action
public ActionResult MeusCursos()
{
Aluno aluno = db.Alunos.FirstOrDefault(a => a.Usuario == User.Identity.Name);
if (aluno != null)
return View("MeusCursos", db.Cursos.ToList());
return View();
}
[HttpPost]
public ActionResult MeusCursos(int id)
{
Aluno aluno = db.Alunos.FirstOrDefault(a => a.Usuario == User.Identity.Name);
if (aluno != null)
return View("MeusCursos", db.Cursos.ToList());
var curso = db.Cursos.FirstOrDefault(c => c.Id == id);
if (curso == null)
return View("MeusCursos");
if (curso.Aprovado == false)
{
ModelState.AddModelError("Aprovado", "Você ainda não concluiu o Curso");
return RedirectToAction("MeusCursos");
}
return View(db.Cursos.ToList());
}
My View
@model IEnumerable<MeuProjeto.Models.Curso>
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
<h2>Meus Cursos</h2>
<table class="table table-hover">
<tr>
<th>
Curso
</th>
<th>
Aluno
</th>
<th>
Aprovado?
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Nome_Curso)
</td>
<td>
@Html.DisplayFor(modelItem => item.AlunoCursos)
</td>
<td>
@Html.DisplayFor(modelItem => item.Aprovado)
</td>
<td>
<div class="btn-group">
<div class="col-md-offset-2 col-md-10">
@if (item.Aprovado == false)
{
<input type="submit" value="Pendente de Aprovação" name="meusCursos" class="cursos btn btn-default" disabled="disabled" data-id="@item.Id"/>
}
else
{
<a href="@Url.Action("GerarPDF", "Aluno")"> <input type="submit" value="Emitir Declaração" name="meusCursos" class="cursos btn btn-success" enable="enable" /> </a>
}
</div>
</div>
</td>
</tr>
}
</table>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$(document).ready(function() {
$(".cursos").click(function() {
$.ajax({
type: "POST",
url: "MeusCursos/",
data: { id: $(this).data("id") },
success: function() {
$(this).attr("enable", "enable");
}
});
});
});
</script>
}
For more details I asked this question here too Problem with Entity Framework Relationship
+Newbie, would you write down the class code in the question, please? This would help us better understand the problem of the student’s name not appearing on the list.
– Ulysses Alves