我正在编写一个 MVC C# 应用程序。我使用母版页并且有
其他页面的标题和内容放在contentPlaceholders中,分别是
显示在母版页上。
在母版页上,我希望将 TitleContent 写在
和 <title> 中。标签
并在 <body> 中部分(在 <h1> 标签中)。
我不被允许这样做,因为出于某种奇怪的原因你不被允许这样做
在页面上使用相同的 contentPlaceholder 两次。
到目前为止,我一直在使用
(FindControl("TitleContent").Controls[0] as LiteralControl).Text
在
中标签,在我开始添加动态内容之前它工作得很好
到 TitleContent 占位符(例如 C# 代码)。
如何让该内容显示两次?
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?
发布评论
评论(2)
如果您要显示的文本位于 ViewData 或视图绑定到的模型中,您也许可以根据需要多次访问它,并将其设置在视图/母版页上的任何元素上。
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.
如果您存储必要的字符串,则可以拥有模型视图类。然后使您的视图具有上述类的类型的强类型。最后在标签 make 中
希望
它有帮助。
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
and
Hope it helps.