views:

248

answers:

2

Hi

I'm writing an MVC C# application. I use a masterPage and have the title and content of other pages put in contentPlaceholders, which are displayed on the master page.

On the MasterPage, I want the TitleContent written in both the <title> tag and in the <body> section (in a <h1> tag).

I'm not allowed to do this, because for some odd reason you're not allowed to use the same contentPlaceholder twice on a page.

Until now, I've been using (FindControl("TitleContent").Controls[0] as LiteralControl).Text in the <h1> tag, which worked fine until I started adding dynamic content to the TitleContent placeholder (eg C# code).

How do I display this content twice?

A: 

If the text you want to display is in ViewData or the Model your views are bound to, you maybe able to access it as many times as you want and set it on any element on your view/master page.

darthjit
A: 

You can have model view class were you store necessary string. Then make you views as strongly typed with the type of the class mentioned above. Finally inside tags make

<title><%=Model.PageName%></title>

and

<h1> <%=Model.PageName%></h1>

Hope it helps.

Jenea
Thank you both for your answers. The trouble is that I'm making a master page for some stand alone web applications that should work like plugins. I want the interface to the master page to be as simple as possible, so modules just load by being put in a file under the views directory (eg. I don't want them to mess with code outside their files). Basically, a module should just provide a title- and contentplaceholder.The web applications have already been written, I'm just trying to gather them in a sort of tool box :-)
Anders Søndergaard
If you find the answer please write it here :).
Jenea