如何在剃须刀代码块中插入空格? [英] How do I insert spaces within a razor Code block?
问题描述
VS2013,MVC5,Razor,VB
VS2013, MVC5, Razor, VB
我要在答案"一词前留空格.如何在以下Razor代码块中强制插入空格?
I want spaces in front of the word 'Answered'. How do I force spaces into the following Razor code block?
@Code If Model.DisplayAnsweredFlag Then
@If Model.Answered Then
@Html.Raw("Answered")
End If
End If
End Code
在html.raw()中,空格本身或前面文本中的空格似乎没有被编码到页面中.但是我也不能在代码块中使用'& nbsp'或'@& nbsp',因为它的语法不正确.
In html.raw(), spaces by themselves or spaces in of front text don't seem to get coded into the page. But I also can't use ' ' or '@ ' in a Code Block because it's incorrect syntax.
如果我使用的技术较差,请提出建议,或者如果有其他获取空格的方法,请提出建议.
If I'm coding with a poor technique, please advise, or if there is a different way to get the spaces in, please advise.
推荐答案
解析HTML时将忽略空格,除非空格出现在pre
块中.如果要填充一些文本,则需要采用以下方法之一:
Spaces are ignored when parsing HTML, unless they occur within a pre
block. If you want to pad some text, you need to take one of the following approaches:
-
将其包装在块级HTML元素(例如
p
或div
)中,然后使用CSS将填充/边距添加到该元素.这是推荐的方法.
Wrap it in a block-level HTML element like
p
ordiv
, and then add padding/margin to the element using CSS. This is the recommended approach.
使用
代替要填充的常规空格.呈现HTML时仅计算不间断空格.但是,这种方法很骇人,不建议使用.
Use
in place of the regular spaces you're trying to pad with. Only non-breaking spaces are counted when rendering HTML. However, this approach is hacky and not recommended.
将文本包装在pre
元素中.然后,将考虑<pre>
和</pre>
标记内的所有空格.但是,这种方法也不可靠,因此不建议使用.
Wrap your text in a pre
element. Then all whitespace within the <pre>
and </pre>
tags will be taken into account. However, this approach is also hacky and not recommended.
这篇关于如何在剃须刀代码块中插入空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!