And*_*i M 4 asp.net asp.net-mvc razor
我在VS2012中创建了两个应用程序
现在我打开任何.cshtml文件并添加以下代码:
<div>
@if (true)
{
@string.Format("{0}", "test")
}
</div>
Run Code Online (Sandbox Code Playgroud)
它在应用程序#1(mvc3)中工作正常,我看到"test"字显示.但它在Application#2(mvc4)中不起作用.
任何人都能解释为什么会发生这种情况以及应该改变什么?
更新:我刚刚发现了一个非常奇怪的事情.如果用@ String.format("some text")替换@ string.format("some text"),一切正常(注意大写字符串)
升级时我们遇到了类似的问题......看起来简单的写入@string.Format("{0}", "test")将不再像在MVC3中那样直接写入页面.你必须做这样的事情:
<div>
@if (true)
{
Html.Raw(string.Format("{0}", "test"));
}
</div>
Run Code Online (Sandbox Code Playgroud)
要么
<div>
@if (true)
{
<text>@string.Format("{0}", "test"))</text> //added @ to evaluate the expression instead of treating as string literal
}
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2831 次 |
| 最近记录: |