Alternative to ViewBag.Title in ASP.NET MVC 3

Viewed 36918

By default the new project template for ASP.NET MVC 3 adds the following to the default layout (masterpage in razor):

<title>@ViewBag.Title</title>

The view must then contain the following to assign the title of the page, for instance:

@{
     ViewBag.Title = "Log On";
}

Perhaps it is just my own preference but I find that using the ViewBag to hold the title a little bit wrong (I'm thinking too much magic-string flavor). So my question is: Is this the recommended best practice for people using ASP.NET MVC 3 and razor (using a dynamic property bag) or are you opting for something more strongly typed (perhaps involving a custom baseclass?)

8 Answers
Related