By default the new project template for ASP.NET MVC 3 adds the following to the default layout (masterpage in razor):
@ViewBag.Title
<
I also do not use the ViewBag, at all.
At the top of _Layout.shtml ...
@model .Models.Base.EveryPageViewModel
In _Layout.shtml ...
@Model.Title
In your Model ...
///
/// Index View Model
///
public class IndexViewViewModel : EveryPageViewModel {
}
In EveryPageViewModel
///
/// Every Page View Model
///
public abstract class EveryPageViewModel {
///
/// Title
///
public string Title { get; set; }
///
/// Sub Title
///
public string SubTitle { get; set; }
}
In your controller action
///
/// Index
///
///
public ActionResult Index() {
var model = new IndexViewViewModel();
model.Title = "Home";
return View(model);
}