I'd like the end-user to type in text without any formatting in a text area in my ASP.NET MVC application. However, I would like to retain any line breaks or paragraphs that they have created when typing in their text.
If I use a textarea without allowing HTML input, by default, the line breaks and paragraphs are not retained when this text is saved to the database or read back to be displayed on the user interface.
If I AllowHTML, I run the risk of code injection.
The only other way I can think of implementing this is to not AllowHTML but instead have a custom attribute that checks allows only for <p> tags and <br /> tags, but then for implementing that, simple as it might seem, I will have to maintain a dictionary of all possible HTML tags and, with the nature of the Web being so volatile, god knows what other syntactical tokens from CSS or something.
Am I over-complicating the issue? Is there something out of the box or is there an easier way to implement this?
I am using ASP.NET MVC 5.2.3 targeting ASP.NET 4.5.
<div>@Model.SomeProperty</div>) you don't see them, its because you need to style the element withwhitespace:pre;\n\r, not\n) with a<br/>tag :)