I’ve got the following in my Layout file:
@{
ViewBag.Title = "Default page title";
}
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
</head>
.....
In my View I’ve got:
@{
ViewBag.Title = "Home";
Layout = "~/Views/Shared/_Layout.cshtml";
}
However, the page title is coming out as “Default page title”.
How can I get the page title to display as “Home”? I only want “Default page title” to appear if I haven’t specified a value for ViewBag.Title in the View.
Try this