MVC3 Razor:在代码块中显示 html [英] MVC3 Razor: Displaying html within code blocks
本文介绍了MVC3 Razor:在代码块中显示 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 cshtml 文件中,我有很多这样的块:
In my cshtml files I have a lot of blocks with stuff like this:
@if(Model.foo)
{
<span>Hello World</span>
}
span 存在的唯一原因是因为我找不到任何其他方法来强制它识别Hello World"是 html 的一部分,除非我将它括在 html 标签中.有没有一种不涉及向显示添加无意义标签的代码转义的好方法?
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?
推荐答案
你可以使用 @:
来转义:
You could use @:
to escape:
@if(Model.foo)
{
@:Hello World
}
或未在响应中输出的特殊
标签:
or the special <text>
tag which is not outputted in the response:
@if(Model.foo)
{
<text>Hello World</text>
}
这篇关于MVC3 Razor:在代码块中显示 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文