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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:42:00+00:00 2026-05-27T08:42:00+00:00

I am having a problem with the <text> tag. The following code will not

  • 0

I am having a problem with the <text> tag. The following code will not run due to the </tr> tag near the bottom. If i remove it, it works but it then prints an incorrect table. If i leave it i get the following error: Encountered end tag “tr” with no matching start tag. Are your start/end tags properly balanced?

How can i tell razor to ignore such things?
(I also tried to add a text tag around the /tr and also around all html code but that produces this: Encountered end tag “text” with no matching start tag. Are your start/end tags properly balanced?

@{                             
int i = 0;
foreach (var item in Model.Model)
{
    if (i % 2 == 0)
    {
        <text><tr class="alternate-row"></text>
    }
    else
    {
        <text><tr></text>
    }

        <td>
            <input type="checkbox" />
        </td>
        <td>
            @item.Firstname
        </td>
        <td>
            @item.Surname
        </td>
        <td>
            <a href="">george@mainevent.co.za</a>
        </td>
        <td class="options-width">
            <a href="" title="Edit" class="icon-1 info-tooltip"></a><a href="" title="Edit" class="icon-2 info-tooltip">
            </a><a href="" title="Edit" class="icon-3 info-tooltip"></a><a href="" title="Edit"
                class="icon-4 info-tooltip"></a><a href="" title="Edit" class="icon-5 info-tooltip">
                </a>
        </td>        
    </tr>

}      
}    

Update with another question

Why does Razor even test html-tags?

  • 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-05-27T08:42:01+00:00Added an answer on May 27, 2026 at 8:42 am

    You can do this

    <tr@if (i % 2 == 0) { <text> class="alternate-row"</text> }>
    

    or you can set a variable that “holds” your extended html for the <tr> tag like this

    int i = 0;
    foreach (var item in Model.Model)
    {
        string ext = "";
        if (i % 2 == 0)
        {
            ext = " class=\"alternate-row\"";
        }
    
        <tr@ext>
        // ...
    

    Thats the simplest solution, or you can create a custom html helper.

    More information: Creating Custom HTML Helpers

    Update

    Darin said too, what he would create a custom html helper.

    I suggest that too, if you need that more than one time.

    conclusion

    first choice is to create a html helper, second is to use my first
    approach (inline if statement) and at last to use a variable.

    It does not really depends on “how often” you need that, but if you really need
    that only one time, choose the first approach.
    Every of the three solutions are correct, its your decision depending on the time
    you have.

    hope this helps you

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

Sidebar

Related Questions

I'm having a problem similar to but not quite the same as one I've
I'm having a strange problem where a user can enter the following text Test
Greetings! I'm having a problem getting a text value of a captcha from a
I'm having a problem using the java.text.MessageFormat object. I'm trying to create SQL insert
I'm having a problem aligning an image to the top the text in an
I'm having a problem displaying data from a function to text box within a
I'm having a problem where instead of reading a text file from the location
I'm having a strange problem in that I have php inserting text into a
I am having problems with text with multiple lines not reformatting properly when I
I am having a problem getting onprogress event for the audio tag working on

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.