0
My application that manages Courses is making that mistake O item de modelo passado para o dicionário é do tipo 'System.Collections.Generic.List'1 [MeuProjeto.Models.Curso] ", mas este dicionário requer um item de modelo do tipo' System.Collections.Generic.IEnumerable'1 [MeuProjeto .Models.AlunoCurso] '. What happens is I have one View
who returns to the pupil the courses he is enrolled in, and on that list has a button that is qualified as soon as the administrator approves the student in a course, but when I debugo
give this error above.
My Action
public ActionResult MeusCursos()
{
Aluno aluno = db.Alunos.FirstOrDefault(a => a.Usuario == User.Identity.Name);
if (aluno != null)
{
//O ERRO no DEBUG cai aqui nessa linha.
return View("MeusCursos", aluno.AlunoCursos.Select(ac => ac.Curso).ToList());
}
return View();
}
My View
@model IEnumerable<MeuProjeto.Models.AlunoCurso>
@{
Layout = "/Views/Shared/_Layout.cshtml";
}
<h2>Meus Cursos</h2>
<table class="table table-hover">
<tr>
<th>
Curso
</th>
<th>
Aprovado?
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Curso.Nome_Curso)
</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", "AlunoCursos")"> <input type="submit" value="Emitir Declaração" name="meusCursos" class="cursos btn btn-success" enable="enable" /> </a>*@
<a href="~/AlunoCursos/[email protected]" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-print"></span></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>
}
So @Maicon, it’s because on my membership table Hallucinogenic has the fields Alunoid, Cursoid and Approved. I need to take the field Approved from this table and list the courses.
– Novato
and what’s the problem with returning Hallucinogenic ?
– Maicon Carraro
It worked @Maicon, I had changed the code in the wrong place. I can talk to you via chat?
– Novato
Yes we can, come on
– Maicon Carraro
Call me on Chat @Maicon, I still don’t know what to call you!
– Novato
Let’s continue this discussion in chat
– Maicon Carraro