locked
Razor how to display model data as a table RRS feed

  • Question

  • User-1104215994 posted

    Hi guys,

    I am trying to display my model data as a table row by row. Here is my code below. Is there anyone who can show me how to do it?

    row by row, 3 cells inside of a row

    <div class="col-sm-2 c217">
            @if (Model.lines != null)
            {
                <h3>Results</h3>
    
                for (int i = 0; i < Model.lines.Count(); ++i)
                {
                    for (int k = 0; k < Model.lines[i].products.Count(); ++k)
                    {
                        if (Model.lines[k].products != null)
                        {
                            <tr>
                                <td>
                                    @Model.lines[i].products[k].name
                                </td>
                                <td>
                                    @Model.lines[i].products[k].master_count
                                </td>
                                <td>
                                    @Model.lines[i].products[k].count
                                </td>
                            </tr>
                        }
                    }
                }
            }
    
        </div>

    Best Regards.

    Wednesday, January 9, 2019 8:01 AM

Answers

  • User-1104215994 posted
    <div class="col-sm-2 c217">
            @if (Model.lines != null)
            {
                <h3>Results</h3>
                <table class="table table-bordered table-responsive table-hover">
                    @for (int i = 0; i < Model.lines.Count(); ++i)
                    {
                        for (int k = 0; k < Model.lines[i].products.Count(); ++k)
                        {
                            if (Model.lines[k].products != null)
                            {
                                <tr>
                                    <td>
                                        @Model.lines[i].products[k].name
                                    </td>
                                    <td>
                                        @Model.lines[i].products[k].master_count
                                    </td>
                                    <td>
                                        @Model.lines[i].products[k].count
                                    </td>
                                </tr>
                            }
                        }
                    }
                </table>
            }
    
    
        </div>

    Adding table tag solved my issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 9, 2019 8:15 AM