User-1330468790 posted
Hi wavemaster,
Since the header text will be rendered as the inner text of an anchor element in html page, you might be interested in
CSS white-space Property.
The white-space
property specifies how white-space inside an element is handled.
You could specify the header text with "\r\n" separator and assign "white-space: pre-line;" to the target anchor element to get your desired layout.
More details, you could refer to below codes.
WebGridView.cshtml:
@using MVCDemo.Models
@model IEnumerable<Student>
<style>
a {
white-space: pre-line;
text-align:center;
display:inline-block;
}
</style>
@{
ViewBag.Title = "WebGridView";
Layout = "~/Views/Shared/_Layout.cshtml";
var grid = new WebGrid(Model);
}
<h2>WebGridView</h2>
@grid.GetHtml(
columns: grid.Columns(
grid.Column("Name"),
grid.Column("Awards"),
grid.Column(columnName: "Grade", header: "Grade \r\n (Last year)".ToString(), format: @<text> @item.Grade </text>)));
Controller Action:
public ActionResult WebGridView()
{
List<Student> lstStudent = new List<Student>()
{
new Student{ Name = "Name1", Awards="Award1", Grade=100, StudentId=1 },
new Student{ Name = "Name2", Awards="Award2", Grade=90, StudentId=2 },
new Student{ Name = "Name3", Awards="Award3", Grade=80, StudentId=3 }
};
return View(lstStudent);
}
Result:

Hope helps.
Best regards,
Sean