ASP.NET MVC2 母版页 - 服务器端脚本未呈现,第一个括号被转义
我有一个母版页,我将其用作模板,以允许我定义每个页面的元标记。我的母版页采用包含元信息的模型,这是我尝试执行以下操作的示例:
<meta name="description" content="<%= Model.description %>" />
<meta name="keywords" content="<%= Model.keywords %>" />
但是,当我在页面呈现后检查 HTML 时,我得到以下信息:
<meta name="description" content="<= Model.description %>" />
<meta name="keywords" content="<= Model.keywords %>" />
如果我删除外部引号从内容中,例如 content=<%= Model.description %>
它呈现数据。它似乎不喜欢周围的引号。
这是母版页的错误吗?如果是这样,最好的替代解决方法是什么?如果不是,我做错了什么?
I have a master page which I am using as a template to allow me to define meta tags per page. My master page takes in a model which contains the meta information, here is an example of what I am trying to do the following:
<meta name="description" content="<%= Model.description %>" />
<meta name="keywords" content="<%= Model.keywords %>" />
However, when I check the HTML once the page is rendered I get this:
<meta name="description" content="<= Model.description %>" />
<meta name="keywords" content="<= Model.keywords %>" />
If I remove the outer quotation marks from the content e.g. content=<%= Model.description %>
it renders the data. It doesn't seem to like the surrounding quotation marks.
Is this a bug with the master pages? If so, what would be the best alternative workaround for this? If not, what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前见过这种情况,这很痛苦。也许您的 head 标签中有一个 runat="sever" 属性,如下所示:
如果您刚刚创建:
那么您不应该看到此行为。
I have seen that before and it is a pain. Probably you have a runat="sever" attribute in your head tag like this:
if you just made it:
then you should not see this behavior.
这一直是一个问题,因为它试图对属性中的内容进行编码。您可以通过执行以下操作来解决此问题:
编辑:这不是 MasterPages 特有的问题。我很久以前在这里发布了一个类似的问题,所以询问它,如果您阅读了接受的答案,您可以看到该框架在 head 标签中具有针对各种项目的特定代码,其中它将具有稍微不同的渲染格式并进行编码数据。
ASP.NET Webform css 链接被损坏
This has always been an issue because it is trying to encode the contents in the attributes. You can get around it by doing this instead:
EDIT: This is not an issue specific to MasterPages. I posted a similar question a long time ago here on SO asking about it and if you read the accepted answer you can see that the framework has specific code for various items in the head tag where it will have a slightly different rendering format and will encode the data.
ASP.NET Webform css link getting mangled