HTML.Encode but preserve line breaks

前端 未结 5 1225
甜味超标
甜味超标 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:14

    Use HttpUtility.HtmlEncode then do the replace.

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

提交回复
热议问题