Nebide Yildiz
Nebide Yildiz

Reputation: 4131

ASP.NET MVC 3 how can I create dynamic attribute name in view in cshtml?

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.

Upvotes: 1

Views: 3304

Answers (2)

Rory McCrossan
Rory McCrossan

Reputation: 337560

Wrap the variable in brackets to make the expression explicit:

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

Upvotes: 3

Alex
Alex

Reputation: 35409

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

Upvotes: 3

Related Questions