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 8461285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:50:18+00:00 2026-06-10T13:50:18+00:00

I am looping through an object passed to the View (I’m using ASP.NET MVC

  • 0

I am looping through an object passed to the View (I’m using ASP.NET MVC 3) and creating a Nav Tab using Bootstrap.

At the moment, the actual TABS work and render fine. The tab-content however doesn’t get displayed – Or one of them will if I make it’s class “active” which basically shows the current tab-content (It doesn’t change when I click on a different tab).

What I want to happen: Click on a tab -> It’s content appears.

What currently happens: Click on a tab -> Nothing shows unless I change a tab-content’s class to active (like i mentioned earlier).

Below is my code:

<div>
<ul class="nav nav-tabs">
    @for (int i = 0; i < 1; )
    {
        foreach (var cat in Model.MyObject)
        {
            if (i == 0)
            {
                <li class="active"><a href="#@cat.Name" data-toggle="tab">@cat.Name</a></li>
                i++;
            }
            else
            {
                <li><a href="#@cat.Name" data-toggle="tab">@cat.Name</a></li>
            }
        }
    }

</ul>
<div class="tab-content" style="overflow: visible;">
    @for (int i = 0; i < 1; )
    {
        foreach (var cat in Model.Model.MyObject)
        {
            if (i == 0)
            {
                <div class="tab-pane active" id="#@cat.Name">@cat.Name</div>
                i++;
            }
            else
            {
                <div class="tab-pane" id="#@cat.Name">@cat.Name</div>
            }
        }
    }
</div>

I put a Breakpoint over each foreach loop – there IS content being passed so that’s not the problem.

How do I modify the code so the content changes when I select a different tab?

EDIT: I have made an IF function that only makes the first one active. As of now, the tabs can switch, BUT, the contents DON’T switch. Only the first content is shown and it won’t change even if I click on another tab.

  • 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-10T13:50:20+00:00Added an answer on June 10, 2026 at 1:50 pm

    I have done a similar thing in cakePHP. You need to specify one of them as active so that when the user loads the page they see the active tab. Then when they click on a different tab the js kicks in and moves the active class to that tab. You can put an if statement in to have it only add the active class to the first tab (or whichever tab you want active by default).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Node.js w/ node_redis and am looping through an object and looking up
I'm looping through an object in javascript and deleting an item that is undefined,
I am looping through an NSString object called previouslyDefinedNSString and verifying if the integer
I'm using iTextSharp to generate PDFs for an ASP.NET application, the PDF generation seems
I have an object with key : value pair. I'm looping through this object
I'm looping through Some xml in .net and assigning Xml elements to string variables.
Per example below...Looping through an object from a parsed JSON string returns an error
Looping through each id retrieve value of objects in 1 dimentional array and 2
Looking through decimal.py , it uses NotImplemented in many special methods. e.g. class A(object):
Say I'm looping through like 20/30 objects or in any other case where I'm

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.