17

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 Answer 1

32

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

<img alt="section" id="@(section_counter)_Section" src=""
Sign up to request clarification or add additional context in comments.

2 Comments

there it is, first time I've had to use that one. Thanks!
No problem, if it solved your problem please remember to resolve your question by selecting an accepted answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.