Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8612381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:36:46+00:00 2026-06-12T04:36:46+00:00

it will be difficult to explain my problem but I’ll try to be the

  • 0

it will be difficult to explain my problem but I’ll try to be the more explicit as possible. Also sorry for my english…

Actually, I have this array in my view.
Array

The code which retrieve that it the following :

        @foreach (var item in Model)
        {
              TimeSpan result = DateTime.Now - item.OrderDate;

              if (result.Days < 31)
              {            
                    <tr border="1" bgcolor="@Odd">
                       <td> @Html.DisplayFor(modelItem => item.Username) </td>    
                       <td> @Html.DisplayFor(modelItem => item.OrderId) </td>  
                        <td>
                            <ul style="list-style-type:none; padding:0; margin:0">
                                @if (item.OrderDetails != null)
                                {
                                    foreach (var o in item.OrderDetails)
                                    {
                                        if (o.Pack == null)
                                        { 
                                            <li>  @Html.DisplayFor(modelItem => o.Product.Name)  </li>
                                        }
                                        else
                                        {  
                                            <li> <text>Pack</text>  @Html.DisplayFor(modelItem =>  o.Pack.Name)  </li>
                                        }
                                    }
                                }  
                            </ul>             
                        </td>
......... other td.............  
                    </tr>
              }                                        // 1116 = 36 months
              else if (result.Days > 31 && result.Days <= 1116)
              {
                  if (item.OrderDetails != null)
                  {
                      foreach (var a in item.OrderDetails)
                      {
                          if (a.Pack != null)
                          {          


                            <tr border="1" bgcolor="@Odd">    
                                <td> @Html.DisplayFor(modelItem => item.Username) </td>
                                <td> @Html.DisplayFor(modelItem => item.OrderId) </td>  

                                <td> 
                                    <ul style="list-style-type:none; padding:0; margin:0"> 
                                        @if (item.OrderDetails != null)
                                        {
                                            foreach (var o in item.OrderDetails)
                                            {
                                                if (o.Pack != null)
                                                {
                                                <li><text>Pack </text> @Html.DisplayFor(modelItem => o.Pack.Name)</li> 
                                                }
                                            }
                                        } 
                                    </ul> 
                                </td>      
    ......... other td.............                         
         </table>

So, for you know, I have two kind of Product : Product and Pack. In my first IF condition (result.days < 31), I retrieve Pack and Product, like my order number 59 because the order date is less than 31 days. That’s work find.

Now, for my second IF condition >31 & <1116, I want that retrieves me just my PACK. It works fine too, I just have two pack and my product are not display, that’s great (don’t pay attention on unit price and quantity columns, i’ve just forgotten to uncommented some line at the moment where I took the screenshot that’s why there is a price and a quantity where it should have nothing.). But like you can see, it retrieves me the line two times for one order when I am in the second condition, cause I have two foreach one in the other one. How could I pass throught it, just have one ligne like my first condition ?

I don’t know if am I clear… You maybe want to know that I work with two models here. One OrderModel, and one OrderDetailModel.
The first one contains OrderId, OrderDate, Username, ClientId
The second one contain OrderDetailId, OrderId, ProductId, UnitPrice(for product), PackId, UnitPricePack.

Thanks a lot, for your answer, tips, links, whatever…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:36:48+00:00Added an answer on June 12, 2026 at 4:36 am

    This is not needed:

                      foreach (var a in item.OrderDetails) 
                      {    
                          if (a.Pack != null) 
                          {         
    

    If you have an item from 31 days old to 1116 days old, and it has products and no packs, you will still get a tr element, and the Product & Pack column will be empty.

    If that is no good for you then make a bool var, maybe called havePack,

                      var havepack = false,
                      foreach (var a in item.OrderDetails) 
                      {    
                          if (a.Pack != null) 
                          {         
                              havePack = true;
                          }
                      }
                      if (havePack)
                      {  //now make your <tr> element here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This will be a bit difficult to explain but I will try my best.
I am having difficulty to explain this problem, but I will try anyway. I
Its a bit difficult to explain, but i will try. Whenever someone clicks on
I have this problem which i find a bit difficult to explain but I
This is a bit of a difficult problem to explain, but I'm hoping it
It is bit difficult to explain, but I'm facing problem in pagination of set
Mmm it's difficult to explain it so I will do my best... I have
Hello I have a question that could seem complicated. But I will try to
This is going to be difficult to explain but hopefully there will be a
I have a slight problem with my application. It is very difficult to explain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.