Well, I'm developing an application that manages Courses , and I'm trying to list where the Courses displays, the Student Name > and the Approved field, where it indicates whether it is approved or not, and on this screen I have to be able to check the checkbox . The problem is that I am not able to make the Student Name list on this list and I can not even edit the Approved field in this list, because when I move the mouse cursor it is ok blocked and I can not check, editing this field on this screen is a must.
MyControllerActionCourse
publicActionResultMeusCursos(){Alunoaluno=db.Alunos.FirstOrDefault(a=>a.Usuario==User.Identity.Name);if(aluno!=null)returnView("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've asked this question here too Problem with relationship Entity Framework