ASP.NET MVC 3 中的元标记
如何让元标记仅适用于一页。如果我想把它放在.aspx文件中,哪里是正确的位置。
谢谢。
How can I put meta tag to work only for one page. If I want to put it .aspx file, where is right place.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您还没有说过,我假设您正在使用 Razor 引擎(新 MVC3 项目的“默认”引擎)。在这种情况下,您只需在布局视图中插入一个新部分,并且仅在需要插入元标记时才渲染该部分。
例如,使用现有的 New ASP.NET MVC 3 项目模板,您可以编辑
Views\Shared\_Layout.cshtml
文件,并在结束之前编辑该文件。 code> 标记,执行如下操作:
然后,在您需要的任何视图中添加以下内容:
如果由于某种原因您仍在使用 ASPX 布局引擎,则可以使用母版页中的
标记和视图中的
标记。编辑:
由于您仍在使用 ASP.NET Forms 布局引擎,因此在 aspx 语法中,这里的基本思想与上面相同:
在母版页中,添加标签:
在 .aspx 视图中,添加新的内容部分(您应该至少有两个——标题和正文):
Since you haven't said yet, I'm assuming you're using the Razor engine (the "default" for new MVC3 projects). In that case, you just need to insert a new section into your layout view, and only render that section if you need to insert a meta tag.
For example, working from the stock New ASP.NET MVC 3 Project template, you would edit your
Views\Shared\_Layout.cshtml
file, and before the closing</head>
tag, do something like this:Then, in any of your views that you needed to, add this:
If you're still using the ASPX layout engine for some reason, you can accomplish the same thing using the
<asp:ContentPlaceHolder>
tags in your master page and<asp:Content>
tags in your views.EDIT:
Since you're using the ASP.NET Forms layout engine still, here's the same basic idea as above in aspx syntax:
In your master page, you add the tag:
And in your .aspx views, you add a new content section (you should already have at least two -- a title and a body):
我打算准确地建议迈克尔所说的(+1)。另一种选择是在 ViewBag 中放置一个布尔值,例如:
对于您想要强制进入 IE8 模式的页面。
然后在您看来,将元标记包装在条件中。要么
或者
I was going to suggest exactly what Michael said (+1). Another option would be to put a boolean in the ViewBag, something like:
For pages that you want to force into IE8 Mode.
and then in your view, wrap the meta tag in a conditional. either
or