Search code examples
asp.netasp.net-mvcmaster-pages

ASP.NET MVC - View with master page, how to set title?


What is prefered way of setting html title (in head) for view when using master pages?

One way is by using Page.Title in .aspx file, but that requires in master page which can mess with HTML code. So, lets assume no server side controls, only pure html. Any better ideas?

UPDATE: I would like to set title in view NOT in the controller or model.


Solution

  • We ended up with

    <head runat=server visible=false>
    

    in master page.

    This way we can read from Page.Title (Page.Title requires head element to exist, otherwise it throws an exception, checked that with reflector). We then use our own head element - MVC way.