Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax to concatenate a variable with static html

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?

like image 568
Nik Avatar asked Nov 03 '11 19:11

Nik


1 Answers

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

<img alt="section" id="@(section_counter)_Section" src=""
like image 200
Brandon Avatar answered Oct 04 '22 18:10

Brandon