这是一个错误吗?或者它是 ASP.NET 4(或 MVC 2)中的设置?
我最近刚刚开始尝试 T4MVC,我喜欢消除魔术字符串的想法。
但是,当尝试在我的样式表的母版页上使用它时,我得到:
<link href="<%: Links.Content.site_css %>" rel="stylesheet" type="text/css" />
像这样渲染:
<link href="<%: Links.Content.site_css %>" rel="stylesheet" type="text/css" />
而这些渲染正确:
<link href="<%: Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />
<link href="<%: Links.Content.site_css + "" %>" rel="stylesheet" type="text/css" />
看来,只要我在代码段内有双引号,它就可以工作。但是当我在那里放入其他任何东西时,它就逃脱了领先的“小于”。
这是我可以关闭的东西吗?这是一个错误吗?
编辑:
编辑2:
最小情况:
<link href="<%: string.Empty %>" />
与
<link href="<%: "" %>" />
编辑3:
我有一个解决方法,我已经实现了一个HtmlHelper扩展,这样我就可以做到这一点:
<%: Html.StyleSheet(Links.Content.site_css) %>
我更喜欢对intellisens的支持,所以我实际上会坚持下去。现在,我只是想解决这个错误。
I just recently started trying out T4MVC and I like the idea of eliminating magic strings.
However, when trying to use it on my master page for my stylesheets, I get this:
<link href="<%: Links.Content.site_css %>" rel="stylesheet" type="text/css" />
rending like this:
<link href="<%: Links.Content.site_css %>" rel="stylesheet" type="text/css" />
Whereas these render correctly:
<link href="<%: Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />
<link href="<%: Links.Content.site_css + "" %>" rel="stylesheet" type="text/css" />
It appears that, as long as I have double quotes inside of the code segment, it works. But when I put anything else in there, it escapes the leading "less than".
Is this something I can turn off? Is this a bug?
Edit:
This does not happen for <script src="..." ... />
, nor does it happen for <a href="...">
.
Edit 2:
Minimal case:
<link href="<%: string.Empty %>" />
vs
<link href="<%: "" %>" />
Edit 3:
I have a workaround, I have implemented an HtmlHelper extension so that I can do this:
<%: Html.StyleSheet(Links.Content.site_css) %>
I like the support for intellisens better, so I'm actually going to stick with that. Right now, I'm just trying to solve the bug.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为问题出在结肠上。尝试
而不是
.
I think the problem is the colon. Try
<link href="<%= string.Empty %>" />
instead of<link href="<%: string.Empty %>" />.
根据 Gu,
<%:
是 ASP.NET 4.0 的一项功能。尝试以 4.0 为目标,看看是否仍然失败。According to the Gu,
<%:
is a feature of ASP.NET 4.0. Try targeting 4.0 and see if its still failing.从 head 标记中删除 runat="server" 属性。
服务器生成的 head 标记将为任何链接标记呈现 HtmlLink 标记。 href的内容取自源码并经过urlencoded。对于脚本包含,则不执行此操作。
编辑:
如果您无法从 head 标记中删除 runat="server",请按如下方式编写链接标记:
以下给出错误“runat 属性必须具有值 server”
Remove the runat="server" attribute from the head tag.
The server generated head tag will render a HtmlLink tag for any link tag. The content of href is taken from source and urlencoded. This is not done for script includes.
EDIT:
Write your link tags like following if you cant remove the runat="server" from head tag:
The following gives an error "runat attribute must have value server"
对我来说,这看起来像是一个错误,编译后的输出是:
这似乎仅当控件位于
head runat="server"
内时才会发生It looks like a bug to me, the compiled output for that is:
This seems to only happen when the control is inside a
head runat="server"