Line breaks do not appear in MVC Razor view

I have the following string value generated in the controller.

cc.lstchat = "Reply the Number with your question... <br />"; foreach (clsChat item in lstchat) { cc.lstchat =cc.lstchat + item.DisplayNumber+". " + item.ChatItem+" <br/> "; } 

Now I am trying to display above a string value inside a div tag in my view, but it does not display line breaks.

 <div id="divChat" style="width:400px;height:300px;border:double"> @Model.lstchat.ToString() </div> 

enter image description here

+8
html asp.net-mvc razor
source share
2 answers

Try the @Html.Raw method

 @Html.Raw(Model.lstchat) 
+14
source share

Use Html.Raw() , it is used to render any string as HTML.

 `@Html.Raw("input data in here is rendered as HTML only")` 
+4
source share

All Articles