1

In MVC 3, view-cshtml file, I want to create a dynamic id like below. How can I merge "videoItem_" and "@MenuItemIndex" to get "videoId_5" for example?

<div class='videoItem' id='videoItem_@MenuItemIndex'>

EDIT : I only need to add();

<div class='videoItem' id='videoItem_@(MenuItemIndex)'>

Thank you.

2 Answers 2

3

Wrap the variable in brackets to make the expression explicit:

<div class='videoItem' id='videoItem_@(MenuItemIndex)'>
Sign up to request clarification or add additional context in comments.

Comments

3
@for(int i = 0; i < SomeInteger; i++){
    <div class='videoItem' id='videoItem_@(i)'>
}

Comments

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.