MVC: C #: display contentPlaceholder content twice

I am writing an MVC C # application. I use masterpage and have the title and content of other pages placed in contentPlaceholders that appear on the main page.

In MasterPage, I want the TitleContent to be written both in the <title> tag and in the <body> (in the <h1> tag).

I am not allowed to do this because for some strange reason you are not allowed to use the same contentPlaceholder twice on the page.

Until now, I used (FindControl("TitleContent").Controls[0] as LiteralControl).Text a <h1> tag that worked fine until I started adding dynamic content to the TitleContent placeholder (like C # code).

How to display this content twice?

+3
source share
2 answers

If the text you want to display is in the ViewData or in the model to which your views are attached, you may be able to access it as many times as you want and install it on any element on the view / main page.

0
source

You may have a model view class in which you store the required string. Then make sure your views are strongly typed with the type of the class mentioned above. Finally, inside the make tags

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

and

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

Hope this helps.

0
source

Source: https://habr.com/ru/post/1732363/


All Articles