It’s good day today! But… 🙂
I have the following problem: I have a controller that updates a type_text field in a Mysql DB. The user types text in texarea, clicks “Update” and, oh magic, the text is posted to the database. But without a break…
In the controller i have:
[Authorize]
[HttpPost]
public string EditComment(FormCollection formValues)
{
var Commenter = User.Identity.Name;
Int64 id = Convert.ToInt64(Request.Form["id"]);
string formValue = Request.Form["value"];
formValue = formValue.Replace("\r\n", "<br/>").Replace("\r", "<br/>");
comments updateCommnets = db.comments.SingleOrDefault(d => d.id == id && d.commenterName == Commenter);
updateCommnets.comment = formValue;
db.SaveChanges();
return formValue;
}
It’s making me crazy for 2 days…
Can Somebody help me? Thanks a lot!
UPDATED
- I use jeditable to perform inline editing. Example of post string: value=Some+text%0ASome2+text2
I would store the text as is in the database without converting
\r\nto<br/>:Then I would write a custom HTML helper to format the values in the view if necessary to show those comments.
and then in the view: