How to change the list type in Asp.Net MVC

Asked

Viewed 115 times

1

How do I change this kind of listingLista

For this type of list below

inserir a descrição da imagem aqui

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>
}

1 answer

0


There is not much secret. Just change the layout of the data 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> 
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.