I have an input form used for a forum, where users can post messages.
I capture the comment content text using Html.TextAreaFor.
However, when the user creates newlines in the text (by pressing Enter), those newlines aren’t “retained” when I redisplay the new message in the forum.
Is the only solution to replace \n with </br> on the server when processing the message (and if so – how do I go about doing that in the best way?), or is there an automated way of achieving it straight away?
Thank you!
You can do it in two places, either when you accept the data from the user or when you display it. I’d recommend when you get it from them since it will only have to do it once. Either way, you can replace it like this:
It’s as easy as that.