Html.Displayfor() not breaking string line

Asked

Viewed 38 times

0

In this code, the idea is to generate a list of records searching the database and showing in a cshtml the variables, for each item in this Model.
In the Database, strings contain \n (line breaks) only that HTML.Displayfor does not break the line, the text is in one line.
I solved this problem with the tag <pre> but then the font style is different.
There’s another way to make him use\n ? Or there’s another way to structure html to work?

<table id="tableRegistro" style="margin:0; width: 100%; border-collapse:collapse; border-spacing:0;" cellpadding="0" cellspacing="0">
         <tbody>
             @foreach (var item in Model.Objeto.ObjetoDetalhes.AsEnumerable().Where(x => x.Tipo.ToUpper() == "RESUMO DA VISITA"))
                {
                   <tr class="row" style="border:0px;margin-left:0;width:50%">
                       <td style="margin-bottom: -3px; margin-top: -3px;font-size:15px">
                            @Html.DisplayFor(modelItem => item.Registro);
                       </td>
                   </tr>
                }
          </tbody>
</table>
  • 1

    tries to add this style white-space: pre-line in <td>

  • 1

    found out and was responding at the time. but thank you.

1 answer

0


Insert Html.Displayfor() inside a <p> (paragraph) within the <td>.
I removed and used the same id for the paragraph and wrote a CSS for the id.
So he always breaks the line of the written sentences.

<td style="margin-bottom: -3px; margin-top: -3px;font-size:15px">
   <p id="tableRegistro">@Html.DisplayFor(modelItem => item.Registro)</p>                                               
</td>
#tableRegistro {
    white-space: pre-wrap;
}

For more information: MDN Web Doc: white-space

Browser other questions tagged

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