MVC3 ascx 与 razor 页面渲染问题
我有一个可以正确呈现的 aspx 网页。当转换成剃须刀时,它就不会了。这是一个简化的示例(删除了所有无关的内容)。
aspx:
<asp:Content ID="indexContent" ContentPlaceHolderID="ToolContent" runat="server">
<% string test = "<div><b>Tag Test</b></div>"; %>
<h2><%= test %></h2>
</asp:Content>
razor:
@section ToolContent {
@{ string test = "<div><b>Tag Test</b></div>"; }
<h2>@test</h2>
}
aspx 按预期呈现。剃刀仅在标题标签中显示“test”(
Tag Test
)的内容。我认为我对剃须刀的理解是有缺陷的。如果有人可以启发我和/或向我展示解决方案/解决方法,我将不胜感激。
I have an aspx web page that renders correctly. When converted to razor, it does not. Here is a simplified example (stripped of all extraneous stuff).
aspx:
<asp:Content ID="indexContent" ContentPlaceHolderID="ToolContent" runat="server">
<% string test = "<div><b>Tag Test</b></div>"; %>
<h2><%= test %></h2>
</asp:Content>
razor:
@section ToolContent {
@{ string test = "<div><b>Tag Test</b></div>"; }
<h2>@test</h2>
}
The aspx renders as expected. The razor just displays the content of "test" (<div><b>Tag Test</b></div>) in the header tag.
I assume that my understanding of razor is flawed. If someone could enlighten me and/or show me a solution/work around, I would greatly appreciate it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您编写
@test
时,Razor 会自动转义它。为了防止它被转义,请编写
@Html.Raw(test)
。When you write
@test
, Razor automatically escapes it.To prevent it from being escaped, write
@Html.Raw(test)
.