语法来连接具有静态的html变量 [英] Syntax to concatenate a variable with static html
问题描述
我试图建立使用剃刀变量和静态内容混合一些HTML的。
I'm trying to build up a bit of HTML using a mix of razor variables and static content.
下面是我卡住:我有一个计数器变量,我叫视图 section_counter
。我想使用的图像标签我建立的ID。但是不像<%...%GT;
符号我已经习惯了,我只是不能够做什么,我需要。
Here is where I get stuck: I have a counter variable in my view called section_counter
. I want to use that in the ID of the image tag I'm building. However unlike with <% .. %>
notation I'm used to, I'm just not able to do what I need.
<img alt="section" id="@section_counter_Section" src=""..... etc
我需要的ID看起来像 3_Section
。但是,如果我离开的变量和字 _Section
之间的空间,值保留空间( 3 _Section
)。
I need the id to look like 3_Section
. However if I leave a space between the variable and the word _Section
, the value retains that space (3 _Section
).
如果我使用&LT;文字和GT;
提示,我得到这样的:
If I use the <text>
hint, I get this:
<img alt="section" id="3<text>_Section</text>" src="
在我生成的HTML。我缺少什么?
In my generated HTML. What am I missing?
推荐答案
尝试把你的变量在括号中。 (一<一href=\"http://weblogs.asp.net/scottgu/archive/2010/12/16/asp-net-mvc-3-implicit-and-explicit-$c$c-nuggets-with-razor.aspx\">explicit code金块)
Try putting your variable in brackets. (An explicit code nugget)
<img alt="section" id="@(section_counter)_Section" src=""
这篇关于语法来连接具有静态的html变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!