How to jump line with View Bag?

Asked

Viewed 762 times

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 got the following:

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

/n it hasn’t worked to jump the line, someone can help me?

1 answer

5


Do not work because we are returning HTML to the presentation, and no console formatting.

You got two good ways to go:

1. Using the 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 />"))
  • 2

    you shine too man! Thank you so much again!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.