Syntax to concatenate a variable with static html

2019-06-15 04:03发布

I'm trying to build up a bit of HTML using a mix of razor variables and static content.

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

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).

If I use the <text> hint, I get this:

<img alt="section" id="3<text>_Section</text>" src="  

In my generated HTML. What am I missing?

1条回答
Evening l夕情丶
2楼-- · 2019-06-15 04:55

Try putting your variable in brackets. (An explicit code nugget)

<img alt="section" id="@(section_counter)_Section" src=""
查看更多
登录 后发表回答