我在过去几天玩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 – 对博客帖子等等),并使数据驱动.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。