MVC3元标记动态变化 [英] MVC3 Meta tag Dynamically change

查看:117
本文介绍了MVC3元标记动态变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作MVC3中,我使用剃刀引擎我有包含像

I am working on MVC3, I am using Razor engine i have a layout.cshtml page which contains meta tag like

<meta property="og:url" content="http://www.mywebsite.com/" />

我有一些内容页一样abc.cshtml有Layout.cshtml页面,有布局的,所以他们都可以从layout.cshtml meta标签,我想,abc.cshtml应该有自己的meta标签如

I have some content pages like abc.cshtml which has Layout.cshtml page as there's layout,so they are getting meta tags from layout.cshtml,i want that abc.cshtml should have its own meta tag like

<meta property="og:url" content="http://www.mywebsite.com/controller/abc" />

我怎样才能做到这一点?或者我可以动态改变meta标签??????

How can i do this? OR can i change meta tag dynamically??????

推荐答案

是的,你可以从每个或视图操作传递的价值ViewBag像下面...

Yes you can pass that value from each or view action in ViewBag like below...

ViewBag.OgURL = "http://www.mywebsite.com/controller/abc";

然后你layout.cshtml

then in you layout.cshtml

@ViewBag.OgURL

以上head标签中设置你layout.cshtml ..

or set above head tag in you layout.cshtml..

@RenderSection("head", false)

和添加在您的视图...

and add in your view...

@section head {
<meta property="og:url" content="http://www.mywebsite.com/controller/abc" />
}

这篇关于MVC3元标记动态变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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