I want to show text on two separate lines for the page header:
@section featured {
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>@ViewBag.Message</h1>
</hgroup>
</div>
</section>
}
I have the following code in controller:
public ActionResult Login(string returnUrl)
{
StringBuilder sb = new StringBuilder();
sb.Append("Web Security Administration Portal");
sb.AppendLine();
sb.AppendLine();
sb.Append("Services, Inc. - SSOAdmin v2.00");
ViewBag.ReturnUrl = returnUrl;
ViewBag.Message = sb.ToString();
return View();
}
ViewBag
does not show new line. When viewing source code of generated html, looks like that two strings are on separated lines, but when page is rendered, lines are not separated.
I tried to use sb.Append(Environment.NewLine)
and sb.Append(Text{0}, Environment.NewLIne)
as well. Does not help here.
What can be wrong here?
Environment.NewLine
puts the text on multiple lines in the HTML that is created. However, white space such as new lines are ignored by most HTML elements. You should add <br />
where you want new lines.
Alternately, you could change that behavior by adding see to the enclosing element that adds:
white-space: pre-wrap;
The best bet to get that to work would be to have your ViewBag
be wrapped in a <p>
.