The 'tr' element cannot be nested within the 'tr' element

I have a partial view:

@model List<user>

@foreach (var user in Model)
{
    <tr>
        <td>@user.name</td>
        <td>...</td>
    </tr>
}

      

And get this error:

Validation (HTML5): The 'tr' element cannot be nested within the 'tr' element.

This annoys me more than it needs to be, but I want to get rid of it. Installing Updating Web Standards did not help. Any ideas?

Edit This is the main view:

<table>
    <thead>
        <tr>
            <th>@i18n.name</th>
            <th>...</th>
        </tr>
    </thead>
    <tbody id="results">
        @Html.Partial("list_rows", @Model.users)
    </tbody>
</table>

      

This is the generated HTML:

<table>
    <thead>
        <tr>
            <th>naam</th>
            <th>...</th>
        </tr>
    </thead>
    <tbody id="results">


<tr>
    <td>...</td>
    <td>...</td>
</tr>
<tr>
    <td>...</td>
    <td>...</td>
</tr>

    </tbody>
</table>

      

Edit . Pulling the entire page with the W3C validator gives

This document has been successfully validated as HTML5!

+3


source to share


2 answers


This error appears when you open an element <tr>

before skipping your model. So far, the code you are posting is correct and free of errors.



+1


source


Just make sure your code looks something like this:

<table>

@foreach (var user in Model)
{
     <tr>
          <td>@user.name</td>
          <td>...</td>
     </tr>
}

</table>

      



It looks like you already have an open tag where you are trying to add more tags. If you already have tag tags in your table, just make sure they are all closed before starting the loop:

<tr>..</tr>

      

0


source







All Articles