HTML.Encode but preserve line breaks

前端 未结 5 1227
甜味超标
甜味超标 2021-02-01 13:48

I take user input into a text area, store it and eventually display it back to the user.

In my View (Razor) I want to do something like this...

@Message.         


        
5条回答
  •  死守一世寂寞
    2021-02-01 14:20

    You can encode your message, then display it raw. Something like:

    @Html.Raw(Server.HtmlEncode(Message).Replace("\n", "
    "))

提交回复
热议问题