asp.net-mvc – 如何在ASP.NET MVC中传递页面的元标记?

我在过去几天玩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 – 对博客帖子等等),并使数据驱动.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....