skip to Main Content

When adding the category section, each category comes with one. But which element of the category do I want to attract, how can I do it.

I give examples from each category database. Category A has b c url. Category B also has URL b c. I have a table called Menu. If the category is true, I try to match it with the id in the Menu table from my Category table and display it.

Data model:

public static veri.Kategoriler[] deneme
{
    get
    {
        using (burakEntities db = new burakEntities())
        {
            return db.Kategorilers
                     .Include(p => p.Menuler)
                     .OrderByDescending(p => p.kategorilertarih)
                     .Where(p => p.KategoriAktif == "true"
                               & p.Menuler.KategoriMi == "true"
                               & p.Menuler.MenuMi == "false"
                               & p.Menuler.Menulerid == p.Menulerid)
                     .ToArray();
        }
    }
}

_category.cshtml view:

@foreach (var item in Model)
{
    <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
            @item.Menuler.MenuAdi
        </a>

        <!-- Dropdown menu -->
        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
            <li>
                <a class="dropdown-item" href="#">@item.kategoriAdi</a>
            </li>
        </ul>
    </li>
}

Output:

output 1

output 2

2

Answers


  1. Chosen as BEST ANSWER

    problem solved

    @foreach (var item in burak.Models.Data.kategorimi1)
    {
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
                @item.MenuAdi
    
            </a>
            <!-- Dropdown menu -->
            <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
    
                @foreach (var i in burak.Models.Data.deneme)
                {
                    if (item.Menulerid == i.Menulerid)
                    {
    
                        <li>
                            <a class="dropdown-item" href="#">@i.kategoriAdi</a>
                        </li>
                    }
    
                }
            </ul>
        </li>
    }
    

  2. I think you need to place your foreach inside the following code block. You are looping on a higher level; around the UL, thus you get more dropdowns instead of more dropdown-items.

     <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
              @foreach (var item in Model)
              {
                 <li>
                    <a class="dropdown-item" href="#">@item.kategoriAdi</a>
                 </li>
              }
      </ul>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search