如何传递ASP.NET MVC网页的meta标签? [英] How to pass page's meta tags in ASP.NET MVC?

查看:138
本文介绍了如何传递ASP.NET MVC网页的meta标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与ASP.NET MVC打的最后几天,是能够建立一个小网站。一切都很正常。

I'm playing with ASP.NET MVC for the last few days and was able to build a small site. Everything works great.

现在,我需要通过ViewData的传递网页的META标签(标题,描述,关键词等)。 (我使用一个母版页)。

Now, I need to pass the page's META tags (title, description, keywords, etc.) via the ViewData. (i'm using a master page).

如何你处理这件事?谢谢你在前进。

How you're dealing with this? Thank you in advance.

推荐答案

这里是我现在怎么做...

Here is how I am currently doing it...

在母版,我有一个默认的标题,描述和关键字内容占位符:

In the masterpage, I have a content place holder with a default title, description and keywords:

<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>

然后在页面中,您可以覆盖所有这些内容:

And then in the page, you can override all this content:

<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(计算机[的PageTitle]),或将其包含在模型(ViewData.Model.MetaDescription - 是有意义的博客文章等),并使其数据驱动

This should give you an idea on how to set it up. Now you can put this information in your ViewData (ViewData["PageTitle"]) or include it in your model (ViewData.Model.MetaDescription - would make sense for blog posts, etc) and make it data driven.

这篇关于如何传递ASP.NET MVC网页的meta标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆