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

  • Home
  • SEARCH
  • 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 9255451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:43:14+00:00 2026-06-18T11:43:14+00:00

I have been stuck on this for some time now; I’m using ASP.NET MVC

  • 0

I have been stuck on this for some time now; I’m using ASP.NET MVC 4 and C# for a web application. I read in an Excel file from my controller, and I have a List of all the cells which I send back to my view. This is what I’m using:

<table>
@foreach (var item in ViewBag.range)
{ 
    <tr>
    @for (int i = 0; i < 6; i++) 
    {
        <td>
            <input style="width:50px;" value=@item />
        </td>
    }
    </tr>
}
</table>

Basically, I have 6 columns in Excel. I am trying to recreate the Excel in my view.
But there is something wrong with my for loop, it’s doing each cell 6 times.

Can anyone help please?

  • 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-18T11:43:15+00:00Added an answer on June 18, 2026 at 11:43 am

    It does that because you tell it to in the for loop. Perhaps you should remove it.

    <table>
     <tr>
      @foreach (var item in ViewBag.range)
      { 
    
        <td>
            <input style="width:50px;" value=@item />
        </td>
    
      }
     </tr>
    </table>
    

    EDIT

    This will place the items inside of range into rows which have 6 columns each.

    @{
     int total = 0; 
    }
    
    <table>
      @foreach (var item in ViewBag.range)
      { 
        if( total % 6 == 0 ){
            @:<tr>
        }
        <td>
            <input style="width:50px;" value=@item />
        </td>
        if( total+1 % 7 == 0 ){
            @:</tr>
        }
        total++;
      }
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have now been stuck at this for some time so I though to
I have been stuck with this problem for quite some time now and i
I've been using repositories for data access for some time now but have never
I have been stuck with this bug for a long time now, and i
I've been stuck with this for hours now. I think it's time for some
i know this is basic but somehow i have been stuck here for some
I have been stuck on this for a while now and I cannot seem
so i have been stuck with this issue for 3 weeks now and i
I have been stuck for a long time on this simple but obtuse message
I've been working in .NET for some time now, but occasionally I still get

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.