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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:43:19+00:00 2026-06-11T12:43:19+00:00

I am using a simple for loop like this to output a table of

  • 0

I am using a simple for loop like this to output a table of images stored in a database:

@for(var i = 1; i < 7; i++){
<tr>
<td>Image @i:</td>
<td><img src="images/@image01" /></td>
</tr>
}

What I want to do is to use the i variable in the image field name as well because in the above example, obviously each image is the same, coming from the image01 field. I tried the following but it doesn’t work. Does anyone know the correct way to code this?

@for(var i = 1; i < 7; i++){
<tr>
<td>Image @i:</td>
<td><img src="images/@image0@i" /></td>
</tr>
}

I’ve tried various things but I’m just learning razor syntax coming from ASP Classic so I’m just guessing at the moment.

Cheers,
Kev

  • 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-11T12:43:20+00:00Added an answer on June 11, 2026 at 12:43 pm

    If image01 is a field, you can’t dynamically create a variable name, you have to do:

    @for(var i = 1; i < 7; i++){
    string imgName;
    if (i == 0)
       imgName = image01; //store the var in a central variable
    else if (i == 1)
       imgName = image02;
    else if ...
    
    <tr>
    <td>Image @i:</td>
    <td><img src="images/@imgName" /></td>
    </tr>
    }
    

    The only other option is reflection, but I don’t how how that is done in a Razor view.

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

Sidebar

Related Questions

I am using a simple loop that looks like this: $query = SELECT *
I just designed a simple For Loop using window form application. I would like
This is a simple program i wrote using for loop public class Test {
I'm programming a simple text-based RPG using a switch statement for a game loop.
Using simple type like class A { public int X, Y; } with object
im using simple vector push_back to object of Type A and getting this error
I'm using simple_html_dom.php to get all images from an url (like pinterest does) if($_POST['submit'])
If I have a simple code like this: $a = "hi"; for ($i =
This seems like a simple question to ask but, is it generally a good
Using simple field width specifier, the columns are 'thinner' when the string includes 'European'

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.