ASP.Net Core C#: Handling new lines in Razor view
Posted: 21 Mar 2020, 20:52pm - Saturday

I've been programming using PHP for a long time, and its funny I am struggling to do it on ASP.Net Core C#. In PHP, all you need to do is call the function "nl2br()" and that's it.

In this blog, I am reminding myself how to do it in ASP.Net Core C#. There are two ways how to resolve my issue:

Method 1 is adding an css line but this approach is not always applicable.
Method 2 is calling Razor Html.Raw() method. I believe this is a better approach. But be careful of XSS attack on this. Make sure you sanitize before saving to database.

I think that's it... Hope for the readers of this post looking for answers like me will help you as well.