Question

I'm new in ASP.NET MVC 4 and I've got a strange problem.

I want to set title of page with <title>HomePage</title>, but when I run application, instead of HomePage, the title of page is localhost:somePort. Also, when I go to another page, for example HomePage/First, the title is localhost:somePort/First.

It works with <title>@ViewBag.Title</title>, but I'd like to know why the first solution doesn't work. Am I missing something there?

Was it helpful?

Solution

It seems like you have @ViewBag.Title in your MasterLayout.cshtml which contains the value for the <title> tag.

You need to make sure that you set the Title property of the ViewBag in your controller.

e.g.

ViewBag.Title = "HomePage";

Then when the page is rendered you will have your desired title.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top