asp.net MVC 如何在aspx页面的head标签里输出Key为常量的ViewData呢?

asp.net MVC 如何在aspx页面的head标签里输出Key为常量的ViewData呢?

下面是有效的:
<meta name="description" content="<%:ViewData["PageDescription"]%>" /> 

直接放在head里,有效的:
<%:ViewData[BaseConstant.STR_VIEWDATA_PAGEDESCRIPTION]%>

下面使用了常量来代替"PageDescription"
常量定义:public const string STR_VIEWDATA_PAGEDESCRIPTION = "PageDescription";

把下列语句放在body标签里,viewdata能正常输出:
<meta name="description" content= "<%:ViewData[BaseConstant.STR_VIEWDATA_PAGEKEYWORD]%>"  />


同样的语句放在head标签里,viewdata却无法正常输出:
<meta name="description" content= "<%:ViewData[BaseConstant.STR_VIEWDATA_PAGEKEYWORD]%>"  />
直接输出如下:
<meta name="description" content="&lt;%:ViewData[BaseConstant.STR_VIEWDATA_PAGEKEYWORD]%>" />


为什么会这样?如何在aspx页面的head标签里输出Key为常量的ViewData呢?

把head标签里的  runat="server" 删除就可以使用了。
change from

<head runat="server">
<meta name="description" content= "<%:ViewData[BaseConstant.STR_VIEWDATA_PAGEKEYWORD]%>"  />

to

<head>
<meta name="description" content= "<%:ViewData[BaseConstant.STR_VIEWDATA_PAGEKEYWORD]%>"  />
....


微软在搞什么啊??原因是什么呢?bug?

既然是MVC4,那为什么建立masterpage的时候会runat="server"加到head标签里呢?

诗词在线
http://www.chinapoesy.com
诗词在线 |唐诗|宋词|元曲|现代诗歌|外国诗歌
126在线阅读网
http://www.Read126.cn
126在线阅读网 人物传记、古典名著、历史书籍。。。
原文地址:https://www.cnblogs.com/adandelion/p/2241437.html