How to jump line with View Bag?

3

I have the following code

public ActionResult Action1 {
 TempData["msg"] = "Essa parte primeiro.\n Essa parte na linha de baixo.";
 return RedirectToAction("Action2");
}

public ActionResult Action2 {
  if (TempData["msg"] == null)
  {
     TempData["msg"] = "";
  }
  ViewBag.Message = TempData["msg"].ToString();
  return View();
}

My View is the following:

<label style="color:red">@ViewBag.Message</label>

/n has not worked to skip the line, can anyone help me?

    
asked by anonymous 10.06.2015 / 15:59

1 answer

5

They do not work because we're returning HTML for the presentation, not console formatting.

You have two good ways to solve:

1. Using CSS

<label style="color:red; white-space: pre-line">@ViewBag.Message</label>

2. Using String.Replace

@Html.Raw(Html.Encode(ViewBag.Message).Replace("\n", "<br />"))
    
10.06.2015 / 16:08