How to print text within a @if{ } condition in Asp.Net in cshtml file?

Asked

Viewed 1,102 times

3

I have the following situation

<td>
   @Html.DisplayFor(modelItem => item.HoraInicial) às 
   @Html.DisplayFor(modelItem => item.HoraFinal)
   <br />
   @Html.DisplayFor(modelItem => item.HoraInicial2) 
   @if (!item.HoraFinal2.Equals(null))
   {
        QUERO IMPRIMIR UM TEXTO SIMPLES AQUI
        echo "às";
   }
   @Html.DisplayFor(modelItem => item.HoraFinal2)
</td>

I want to print the word at if the condition happens if I know that in PHP it’s easy a echo 'às'; resolves, now in ASP.Net MVC I don’t know?

1 answer

3


May be:

For razor block <text>:

<text>às</text> // pode ser varias linhas de texto entre a tag

or @:, needs to be inside the code block @if(){ // } @while(){ // } etc.:

@if (true)
{
    @:às //uma linha de texto.
}

or tags Html

<span>às</span>
<p>às</p>

in your code:

<td>
   @Html.DisplayFor(modelItem => item.HoraInicial) às 
   @Html.DisplayFor(modelItem => item.HoraFinal)
   <br />
   @Html.DisplayFor(modelItem => item.HoraInicial2) 
   @if (!item.HoraFinal2.Equals(null))
   {
        //QUERO IMPRIMIR UM TEXTO SIMPLES AQUI
        <text>às</text>
   }
   @Html.DisplayFor(modelItem => item.HoraFinal2)
</td>

References:

  • MVC3? It’s kind of old that there, no?

  • @Gypsy omorrisonmendez ancient in which way?

  • 1

    Really old. It’s not wrong, I’m just bothering you :)

  • So, I found this reference, I even looked before a more current one, but, as nothing has changed and now is another type, but, if you have some better reference and can indicate I thank.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.