How to change the list type in Asp.Net MVC

1

How do I change this type of listing

Forthistypeoflistbelow

My View

@model IEnumerable<MeuProjeto.Models.AlunoCurso>
@{
    Layout = "/Views/Shared/_Layout.cshtml";
}

<h2>Aprovar Aluno</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.Curso.Nome_Curso)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Aluno.Nome)
            </td>
            <td>
                @Html.CheckBox("Aprovado_" + item.CursoId, new { @class = "Aprovado", id = item.Id })
            </td>
        </tr>
    }

</table>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

    <script>
        $(document).ready(function () {
            $(".Aprovado").click(function () {
                $.ajax({
                    url: "Aprovar/",
                    type: "POST",
                    data: { id: $(this).attr('id') },
                    success: function(data) {
                        alert("Aprovação feita com sucesso!");
                    }
                });
            });
        });

    </script>
}
    
asked by anonymous 23.06.2015 / 22:07

1 answer

0

There is not much secret. Simply change the data layout by grouping by course:

<h1>Cursos</h1>

@foreach (var item in Model.GroupBy(ac => ac.Curso))
{

    <table class="table table-hover">
        <thead>
            <tr>
                <th>
                    @item.Key.Nome
                </th>
                <th>
                    Aprovado?
                </th>
            </tr>
        <thead>
        <tbody>
            @foreach (var alunoCurso in item.ToList()) {
                <tr>
                    <td>
                        @Html.DisplayFor(_ => alunoCurso.Aluno.Nome)
                    </td>
                    <td>
                        @Html.CheckBoxFor(_ => alunoCurso.Aprovado, new { @class = "Aprovado", id = item.Id })
                    </td>
                </tr>
            }
        </tbody>
    </table> 
}
    
23.06.2015 / 22:57