asp.net mvc 3 - Error in a Foreach loop ASP MVC view -


in view code follows need replace "foreach" loop @ line 243 return once shipment date,carrier , tracking number. code returns shipment date,carrier , tracking number each spipment package. if have 3 packages each line returns 3 times same info on each line. want have them displayed once per shipmentpackage.

i trying learn asp , mvc working on developed project. please let me know if need more info.

@model insite.mvc.models.viewmodels.orderhistorydetailviewmodel @section templatecsscontent { <link href="/styles/template/ma-order-details.css" rel="stylesheet" type="text/css" /> <link href="/styles/print.css" rel="stylesheet" type="text/css" media="print" /> } <div class="midwrapper2"> <div class="contentarea2">     <div class="mavd-wrapper">         @{ html.renderaction("myaccountleftnav", "shared"); }         <div class="contentwrapper2">             <div class="content2">                 <div class="clr lfl w100">                     <h1>                         order detail</h1>                     <div class="return-btn">                         <a class="btn btnstylec btn-back-order" href="@url.action("orderhistory", "account")">                             order list</a></div>                 </div>                 @if (model.erperror.length > 0)                 {                     <div class="clr lfl w100 error">                         @html.raw(model.erperror)                     </div>                 }                 else                 {                     <div class="clr lfl w100">                         <div class="order-number-date">                             <table>                                 <tr>                                     <th class="col-1">                                         <h3>                                             order #:</h3>                                     </th>                                     <td class="col-2">                                         <h3>@model.customerorder.ordernumber</h3>                                     </td>                                 </tr>                                 <tr>                                     <th class="col-1">                                         <h3>                                             order date:</h3>                                     </th>                                     <td class="col-2">                                         <h3>@model.customerorder.orderdate.toshortdatestring()</h3>                                     </td>                                 </tr>                             </table>                         </div>                         @if (model.wsc_showponumber || model.wsc_showtermscode)                         {                             <div class="order-number-date">                                 <table>                                     @if (model.wsc_showponumber)                                     {                                          <tr>                                             <th class="col-1">                                                 <h3>                                                     po#:</h3>                                             </th>                                             <td class="col-2">                                                 <h3>@model.customerorder.customerpo</h3>                                             </td>                                         </tr>                                     }                                     @if (model.wsc_showtermscode)                                     {                                         <tr>                                             <th class="col-1">                                                 <h3>                                                     terms:</h3>                                             </th>                                             <td class="col-2">                                                 <h3>@model.customerorder.termscode</h3>                                             </td>                                         </tr>                                     }                                 </table>                             </div>                         }                     </div>                     <div class="clr lfl w100">                         <div class="bill-ship">                             <table>                                 <tr>                                     <th>                                         <h4>                                             billing information</h4>                                     </th>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.btdisplayname                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @html.raw(model.customerorder.btaddress1)                                     </td>                                 </tr>                                 @if (!string.isnullorempty(model.customerorder.btaddress2))                                 {                                      <tr>                                         <td>                                             @html.raw(model.customerorder.btaddress2)                                         </td>                                     </tr>                                 }                                 <tr>                                     <td>                                         @html.citycommastatezip(model.customerorder.btcity, model.customerorder.btstate, model.customerorder.btzip)                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.btcountry                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.btphone1                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.btemail                                     </td>                                 </tr>                             </table>                         </div>                         <div class="bill-ship">                             <table>                                 <tr>                                     <th>                                         <h4>                                             shipping information</h4>                                     </th>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.stdisplayname                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @html.raw(model.customerorder.staddress1)                                     </td>                                 </tr>                                 @if (!string.isnullorempty(model.customerorder.staddress2))                                 {                                      <tr>                                         <td>                                             @html.raw(model.customerorder.staddress2)                                         </td>                                     </tr>                                 }                                 <tr>                                     <td>                                         @html.citycommastatezip(model.customerorder.stcity, model.customerorder.ststate, model.customerorder.stzip)                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.stcountry                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.stphone1                                     </td>                                 </tr>                                 <tr>                                     <td>                                         @model.customerorder.stemail                                     </td>                                 </tr>                             </table>                         </div>                     </div>                     <div class="clr lfl w100">                         <table class="info-tbl tbl-1">                             <tr>                                 <th class="od-item">                                     item #                                 </th>                                 <th class="od-desc">                                     item description                                 </th>                                 <th class="od-qty">                                     qty ordered                                 </th>                                  @if (model.customerorder.shipmentpackages.count > 0)                                     {                                        <th class="od-ship">                                         ship date                                     </th>                                     <th class="od-pack">                                         carrier                                     </th>                                      <th class="od-track">                                         tracking #                                     </th>                                     }                                  <th class="od-unit">                                     unit price                                 </th>                                 <th class="od-ext">                                     extended price                                 </th>                             </tr>                                @foreach (var orderline in model.customerorder.orderlines)                             {                                  <tr>                                     <td class="od-item">                                         @if (orderline.productroute != null)                                         {                                             <a href="@url.routeurl(null, orderline.productroute)">@orderline.erpnumber</a>                                         }                                         else                                         {                                             @orderline.erpnumber                                         }                                     </td>                                     <td class="od-desc">                                         @orderline.shortdescription                                     </td>                                     <td class="od-qty">                                         @string.format("{0:0}", orderline.qtyordered)                                     </td>                                         @foreach (var shipmentpackage in model.customerorder.shipmentpackages)                                         {                                     <td class="od-ship">                                             @shipmentpackage.shipmentdate.toshortdatestring()                                         </td>                                         <td class="od-pack">                                             @shipmentpackage.carrier                                         </td>                                          <td class="od-track">                                             @if (string.isnullorempty(shipmentpackage.trackingurl))                                             {                                                 @shipmentpackage.trackingnumber                                             }                                             else                                             {                                                 <a target= "_blank" href="@shipmentpackage.trackingurl" >                                                     @shipmentpackage.trackingnumber</a>                                                }                                         </td>                                       }                                     <td class="od-unit">                                         @orderline.actualprice.tocurrency()                                     </td>                                     <td class="od-ext">                                         @orderline.extendedactualprice.tocurrency()                                     </td>                                 </tr>                             }                         </table>                      </div>                     <div class="clr lfl w100">                         <table class="tbl-total">                             <tr class="subtotal">                                 <th class="col-1">                                     subtotal                                 </th>                                 <th class="col-2">@model.customerorder.ordersubtotal.tocurrency()                                 </th>                             </tr>                             @if (model.customerorder.dollarofforder > 0)                             {                                  <tr>                                     <th class="col-1">                                         order discount                                     </th>                                     <th class="col-2">@model.customerorder.dollarofforder.tocurrency()                                     </th>                                 </tr>                             }                             <tr>                                 <th class="col-1">                                     shipping amount                                 </th>                                 <th class="col-2">@model.customerorder.shippingandhandling.tocurrency()                                 </th>                             </tr>                             @if (model.customerorder.dollaroffshipping > 0)                             {                                  <tr>                                     <th class="col-1">                                         shipping discount                                     </th>                                     <th class="col-2">@model.customerorder.dollaroffshipping.tocurrency()                                     </th>                                 </tr>                             }                             <tr>                                 <th class="col-1">                                     sales tax                                 </th>                                 <th class="col-2">@model.customerorder.totaltax.tocurrency()                                 </th>                             </tr>                             <tr class="total">                                 <th class="col-1">                                     order total                                 </th>                                 <th class="col-2">@model.customerorder.ordergrandtotal.tocurrency()                                 </th>                             </tr>                         </table>                     </div>                     <div class="clr lfl w100 order-btns">   <a class="btn btnstyleb btn-print" href="javascript:window.print();">print</a> <a class="btn btnstylea btn-rma" href="@url.routeurl(new { controller = "account", action = "requestrma", orderid = string.isnullorempty(model.customerorder.erpordernumber) ? model.customerorder.ordernumber : model.customerorder.erpordernumber })">                             return request (rma)</a>                     </div>                 }             </div>         </div>     </div> </div> </div> <div class="reverse-footer"> </div> 

replace foreach loop block:

@foreach (var shipmentpackage in model.customerorder.shipmentpackages) {    ... } 

with:

var shipmentpackage = model.customerorder.shipmentpackages.firstordefault(); if (null != shipmentpackage) {     ... } 

hope helps.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -