在asp.net mvc中使用强类型视图数据时设置页面标题

时间:2022-12-04 23:02:10

How can I set the page title in asp.net mvc using strongly typed views AND a master page.

如何使用强类型视图和母版页在asp.net mvc中设置页面标题。

I added a public property to my master page class, but can't seem to get access to it in my view/action.

我在我的母版页类中添加了一个公共属性,但在我的视图/操作中似乎无法访问它。

1 个解决方案

#1


Setup a placeholder in the head of your master page:

在主页面的头部设置占位符:

<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>

Then in your view pages add an asp:Content section:

然后在您的视图页面中添加一个asp:Content部分:

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Model.Title %>
</asp:Content>

#1


Setup a placeholder in the head of your master page:

在主页面的头部设置占位符:

<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>

Then in your view pages add an asp:Content section:

然后在您的视图页面中添加一个asp:Content部分:

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Model.Title %>
</asp:Content>