Reputation: 41
New lines at the start of html fields seem to be ignored by razor.
For example the following new line is ignored.
@{
var value = "\r\nText";
}
<textarea>@value</textarea>
However if I add a space before the new line, the new line is no longer ignored.
@{
var value = " \r\nText";
}
<textarea>@value</textarea>
How can I get the first new line to show without included a space before it?
Upvotes: 2
Views: 121
Reputation: 41
Using the following html helper fixes the problem.
@Html.TextArea("Name", value)
Browsers seem to ignore the first new line due to textarea's commonly being written as:
<textarea>
Value
</textarea>
Upvotes: 2