문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top