我在过去几天玩ASP.NET MVC,并且能够建立一个小型网站.一切都很好
现在,我需要通过ViewData传递页面的META标签(标题,描述,关键字等). (我正在使用母版页).
你怎么处理这个先谢谢你.
解决方法
这是我目前正在做的事情
在主页中,我有一个含有默认标题,说明和关键字的内容占位符:
<head>
<asp:ContentPlaceHolder ID="cphHead" runat="server">
<title>Default Title</title>
<meta name="description" content="Default Description" />
<meta name="keywords" content="Default Keywords" />
</asp:ContentPlaceHolder>
</head>
然后在页面中,您可以覆盖所有这些内容:
<asp:Content ID="headContent" ContentPlaceHolderID="cphHead" runat="server">
<title>Page Specific Title</title>
<meta name="description" content="Page Specific Description" />
<meta name="keywords" content="Page Specific Keywords" />
</asp:Content>
这应该给你一个如何设置的想法.现在,您可以将此信息放在ViewData(ViewData [“PageTitle”]中),或将其包含在您的模型中(ViewData.Model.MetaDescription – 对博客帖子等等),并使数据驱动.
