I come from a procedural PHP background. I am trying to learn how to do the same stuff I used to do in php and do it in asp.net. I need to sort my orders under their perspective Customer name. Right now my layout is:
- Sams Club
- Order 1
- Sams Club
- Order 2
- Walmart
- Order 1
- Walmart
- Order 2
- Walmart
- Order 3
I need my layout more like:
- Sams Club
- Order 1
Order 2
Walmart
- Order 1
- Order 2
- Order 3
I can easily do this with PHP but am struggling to figure out how to do this in an MVC type of application. This is how my cshtml page looks.
<table class="table table-condensed" style="border-collapse:collapse;">
<thead>
<tr>
<th><input type="checkbox" name="CheckOrders" />Select All </th>
<th>Bill to Name</th>
<th>Qty Ordered</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr data-toggle="collapse" data-target="#@Html.DisplayFor(model => item.customer_number)" class="accordion-toggle">
<td><input type="checkbox" name="checkAllCus" value="@Html.DisplayFor(model => item.customer_number)"/></td>
<td>
@Html.DisplayFor(model => item.Bill_to_Name)
</td>
<td>
@Html.DisplayFor(model => item.Quantity_Ordered)
</td>
</tr>
<tr>
<td colspan="12" class="hiddenRow">
<div class="accordian-body collapse" id="@Html.DisplayFor(model => item.customer_number)">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>Order Number</th>
<th>Bill to Name</th>
<th>Qty Ordered</th>
<th>Ship Date</th>
<th>Item #</th>
<th>Description</th>
<th>State</th>
<th>Carrier</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="orders[]" value="@Html.DisplayFor(model => item.order_no)" /></td>
<td>
@Html.DisplayFor(model => item.order_no)
</td>
<td>
@Html.DisplayFor(model => item.Bill_to_Name)
</td>
<td>
@Html.DisplayFor(model => item.Quantity_Ordered)
</td>
<td>
@Html.DisplayFor(model => item.Ship_Date)
</td>
<td>
@Html.DisplayFor(model => item.item_no)
</td>
<td>
@Html.DisplayFor(model => item.descr1)
</td>
<td>
@Html.DisplayFor(model => item.shipstate)
</td>
<td>
@Html.DisplayFor(model => item.shipper)
</td>
<td>
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ })
</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
}
</tbody>
</table>
Below is my Model
namespace OpenCustomerOrder3.Models
{
using System;
public partial class spOrderDetails_Result
{
public string cusNo;
public string customer_number { get; set; }
public string shipper { get; set; }
public string user_def_fld_5 { get; set; }
public string item_no { get; set; }
public string descr1 { get; set; }
public string location1 { get; set; }
public string Bill_to_Name { get; set; }
public Nullable<decimal> Quantity_Ordered { get; set; }
public string Requested_Date { get; set; }
public string Ship_Date { get; set; }
public string Status { get; set; }
public string order_no { get; set; }
public string shipstate { get; set; }
}
}
Bill_to_Name?