1

I am a young developer on asp.net MVC C#, now I'm getting stuck with this part of my code. I have one field in database which data type is 'nText'. Now I query this field to my view. But the text is not include the new line, actually the data is insert to the field by text box with the new line(ENTER).

This is my block code :

<% 
 string overview = Model.ItemDetail.Notes;
%>
<%= overview %>

Can anyone solve it please. Thanks.

Nothing
  • 2,644
  • 11
  • 64
  • 115
  • Are you saying the the text that is being displayed is ignoring "NEWLINE" character and everything is getting displayed inline ? – Pawan Mishra Nov 17 '11 at 04:27

1 Answers1

2

Correct me if I'm wrong. You may use <pre><%= overview %></pre> or replace \r\n with <br/>.

<% 
 string overview = Model.ItemDetail.Notes.Replace(@"\r\n", "<br/>");
%>

OR

<% 
 string overview = Model.ItemDetail.Notes.Replace(Environment.NewLine, "<br/>");
%>
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
  • 1
    I would use Environment.NewLine instead of \r\n. – lahsrah Nov 17 '11 at 04:31
  • 1
    @AVD: It's work perfectly with this :
    <%= overview %>
    . Thanks AVD
    – Nothing Nov 17 '11 at 04:39
  • @socheata Different environments can have different characters for newlines so its a good practice to not hard code it. Have a look here for more info: http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx – lahsrah Nov 17 '11 at 22:28