Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write HTML line using Razor?

I am working on a table according to the molds of the image below

enter image description here

However, to adapt the different amounts of lines in line 3 I made this code

<tbody>
        @{var foco = 3;}


        @for (int x = 0; x < foco; x++)
        {
            <tr>
                @{if (x == 0) {"<td rowspan='" + foco + "' class='col-md-3'>1</td>";}}
                <td class="col-md-2">2</td>
                <td class="col-md-5">3</td>
                <td class="col-md-2">4</td>
            </tr>
        }
    </tbody>

How can I make the if text to be displayed on the screen?

edit: In short, my goal is that I can make a table in which one of the fields has 3 other equivalent fields (can have more or less depending on the need), and for this I need the code above to create these fields unified for me, but I can not perform this 3td process are aligned with 1td higher

like image 232
Lucas Avatar asked Jan 28 '23 12:01

Lucas


1 Answers

You don't want the HTML to be a literal string in the server-side code. Instead, you want your server-side code to simply wrap your normal HTML markup. Pretty much identical to the syntax you already use in your for structure, the only difference being that you also appear to want to output a value within the HTML. The same @-notation is used for that as well.

Something like this:

@for (int x = 0; x < foco; x++)
{
    <tr>
        @if (x == 0)
        {
            <td rowspan="@foco" class="col-md-3">1</td>
        }
        <td class="col-md-2">2</td>
        <td class="col-md-5">3</td>
        <td class="col-md-2">4</td>
    </tr>
}

(Note that this isn't really a C# thing, this is specific to Razor view engine syntax.)

like image 180
David Avatar answered Jan 31 '23 07:01

David