MVC3剃刀:code块中显示HTML [英] MVC3 Razor: Displaying html within code blocks
本文介绍了MVC3剃刀:code块中显示HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我CSHTML文件,我有很多块,像这样的东西:
In my cshtml files I have a lot of blocks with stuff like this:
@if(Model.foo)
{
<span>Hello World</span>
}
的唯一原因跨度有,因为我无法找到任何其他的方式来迫使它认识到Hello World的是HTML的一部分,除非我围绕着它的HTML标签。有没有逃脱code,不涉及增加无意义的标签显示的好办法?
The only reason the span is there is because I can't find any other way to force it to recognize that "Hello World" is part of the html unless I surround it in html tags. Is there a good way to escape the code that doesn't involve adding meaningless tags to the display?
推荐答案
您可以使用 @
逃跑
@if(Model.foo)
{
@:Hello World
}
或特殊&LT;文字和GT;
标签中未响应输出:
or the special <text>
tag which is not outputted in the response:
@if(Model.foo)
{
<text>Hello World</text>
}
这篇关于MVC3剃刀:code块中显示HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文