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

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 keyword to if the if condition happens, I know that PHP is easy echo 'às'; resolves, now ASP.Net MVC / p>     

asked by anonymous 27.01.2017 / 23:56

1 answer

4

They can be:

By 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:

28.01.2017 / 00:04