How to make Html.DisplayFor display line breaks?

后端 未结 8 1522
梦谈多话
梦谈多话 2020-12-04 21:53

Embarrassingly newbie question:

I have a string field in my model that contains line breaks.

@Html.DisplayFor(x => x.MultiLineText)         


        
8条回答
  •  独厮守ぢ
    2020-12-04 21:59

    i recommend formatting the output with css instead of using cpu consuming server side strings manipulation like .replace,

    just add this style property to render multiline texts :

    .multiline
    {
       white-space: pre-wrap;
    }
    

    then

    my multiline text

    newlines will render like br elements, test it here https://snippet.run/xaf4

提交回复
热议问题