I have a textarea where the user can type in input but if they create a newline in the text area I want it to be saved into to the database so it will appear with the newline. How do I do that?
It seems when the string is saved to the data base the /n is removed from the string.
Im using C# with EF6
gfdh
hgfd
hgfd
hgfd
;
This above is what shows in html but the physical display of it is just one line without the newlines
I have tried the br solution but its within the quotes and the br tag is useless if its within the tags. how do I get teh br tag to escape
public void SendMessageToUser(Message message)
{
var db = new database();
var list = db.Conversations.FirstOrDefault(c => c.UserAId == message.SenderId && c.UserBId == message.ReceiverId || c.UserAId == message.ReceiverId && c.UserBId == message.SenderId);
if (list != null)
{
message.ConversationId = list.ConversationId;
message.DateSent = DateTime.Now;
db.Messages.Add(message);
}
else
{
var conversation = new Conversation();
conversation.DateStarted = DateTime.Now;
conversation.ConversationStatusId = 1;
conversation.UserAId = message.ReceiverId;
conversation.UserBId = message.SenderId;
message.ConversationId = db.Conversations.Add(conversation).ConversationId;
message.MessageStatusId = 1;
message.DateSent = DateTime.Now;
db.Messages.Add(message);
}
db.SaveChanges();
}
public class Message
{
public int MessageId { get; set; }
public string Content { get; set; }
public DateTime DateSent { get; set; }
[ForeignKey("Conversation")]
public int ConversationId { get; set; }
public virtual Conversation Conversation { get; set; }
public int MessageStatusId { get; set; }
public virtual MessageStatus MessageStatus { get; set; }
[ForeignKey("Sender")]
public int SenderId { get; set; }
public virtual User Sender { get; set; }
[ForeignKey("Receiver")]
public int ReceiverId { get; set; }
public virtual User Receiver { get; set; }
}
html
@foreach (var m in Model.Messages)
{
<h3>@m.Sender.Username</h3>
<p>@m.DateSent.ToShortTimeString()</p>
@string.Format("{0}",m.Content);
@m.Content;