Search code examples
asp.net-mvchtmlrazorrazorengine

Get New line in Label HTML


I am saving the text from Textarea. And the text is also stored with new line as well as:

   text= "Line1\nLine2"

I am getting Data from Database in the above format. But how can I use the new line to show it on screen <label>@text</label>

Here is the JSFiddle link for my question: http://jsfiddle.net/rjha999/J8kRw/

I am fetching that data on server side in form like ::

 var model = db.GetDossierHeadeRemarks.Select(remarks => new NotesViewModel {
                UserName="RJ",
                Remark=remarks.Remark.Replace("\n","<br/>")
                }).ToList();

But in my View page I am showing this form of data as::

<label class="RemarkContent">@item.Remark</label>

But the Result I am getting is as::

enter image description here


Solution

  • Use the @Html.Raw() helper method.

    <label class="RemarkContent">@Html.Raw(item.Remark)</label>