views:

267

answers:

4

In an ASP.NET MVC view I have the following code:

<% Page.Title = ViewData.Model.MyPageTitle; %>

and when I step through it I see the Page.Title value changing to the title that I want but when you look at the page's title shown in the browser it has not been modified. It appears that this value is overwritten by something later on.

Any ideas how the page title should be set if you want to do it dynamically?

+2  A: 

Have a look at this answer to a similar question.

Matt Hamilton
+1  A: 

Check out Phil Haaaaaaaack's blog post and the responses in the comments over at TipJar: Title Tags and Master Pages for a couple more options.

+1  A: 

I would recommend 2 options.

First would to set something up in your master page that did something like this.

<% Page.Title = ViewData["Title"] ?? "Default title"; %>

Or set up a content placeholder in the head/title section that you could implement in your views to set the title with HTML.

Chad Moran
A: 

why don't you make contentplaceholder of head area in master then you can define title in every page that inherits that master...

cheers

Marko