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="<%:ViewData[BaseConstant.STR_VIEWDATA_PAGEKEYWORD]%>" /> 为什么会这样?如何在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="<%:ViewData[BaseConstant.STR_VIEWDATA_PAGEKEYWORD]%>" /> 为什么会这样?如何在aspx页面的head标签里输出Key为常量的ViewData呢?
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标签里呢?
Remove the runat="server" :<head>