Home MVC Razor with a table element and a list of objects with a list of objects inside
Reply: 0

MVC Razor with a table element and a list of objects with a list of objects inside

user1868
1#
user1868 Published in June 20, 2018, 1:30 am

I've got a list of objects with a list of objects inside.

I have a table and trying to show the list and the list inside.

I get a red squiggly under the 2nd @foreach of the embedded list and a parse error when calling the controller function from JavaScript in a .cshtml.

Why is this invalid? I tried putting it into a row tag, but no luck.

@model IEnumerable<DashBoard.Models.CustomerOrdersViewModel>
@using DashBoard.Helpers;

<table class="table table-hover">
    @foreach (var mdHeader in Model)
    {
        <thead>
            <tr>
                <td>Customer Name</td>
                <td>Customer Image</td>
                <td>Order Date</td>
            </tr>
        </thead>
        <tr>
            <td>@mdHeader.CustomerName</td>
            <td><img class="rounded img-thumbnail" src="@string.Format("/Images/Customers/{0}", @mdHeader.CustomerImage)" alt="" style="width:50px; height:60px;" /></td>
            <td>@mdHeader.OrderDate</td>
        </tr>

        @foreach (var mdDetail in mdHeader.OrderDetailsViewModel)
        {
            <tr>
                <td>@mdDetail.Quantity</td>
                <td>@mdDetail.ProductName</td>
                @* Concern: How is the path to the image determined? *@
                <td>@Html.ProductImage(@mdDetail.ProductType, @mdDetail.ProductImage, "60px", "58px") </td>
            </tr>
        }
    }
</table>

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308246 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO