Reputation: 2695
In an ASP MVC3 application I have the following contoller action:
public JsonResult GetJsonStatus(string id)
{
var statuses = repo.GetEventLogMessages(new Guid(id));
StringBuilder sb = new StringBuilder();
foreach (string status in statuses)
{
sb.AppendLine(status);
}
StatusMessage sm = new StatusMessage { Status = sb.ToString(), Processing = importing };
return Json(sm,JsonRequestBehavior.AllowGet);
}
In the Json that is returned, Status can be multiple lines of text that gets put into a Textarea. Here is the relavant portion of the view with the JQuery:
@model RAM.Models.StatusMessage
<table cellpadding="2" cellspacing="0" border="1">
<tr>
<td>
<textarea id="status" cols="30" rows="7" wrap="off" class="statusText" >@Model.Status</textarea>
</td>
</tr>
</table>
<script type="text/javascript">
function getStatus(processID) {
var url = '@(Url.Action("GetJsonImportStatus"))' + '/' + processID;
$.getJSON(url, null, function (data) {
$('#status').text(data.Status);
});
}
</script>
The problem is that the text that ends up in the text area will have a leading space on each line except the first so it will look somthing like this:
This is line1
This is line2
This is line3
The value of Status in the Json looks like this: "This is line1\r\nThis is line2\r\nThis is line3\r\n"
How do I remove or prevent the leading spaces?
Upvotes: 0
Views: 304