Reputation: 2354
I try to add number into name attribute of html element in razor.
@for (int j = 1; j <= numberOfTravelers; j++)
{
<input type="text" name="FirstNameEN@j" class="input-text full-width" value="" placeholder="First Name" />
}
In this case razor can not detect j number. How to fix this?
Upvotes: 0
Views: 217
Reputation: 18873
Use @()
as shown :-
@for (int j = 1; j <= numberOfTravelers; j++)
{
<input type="text" name="FirstNameEN@(j)" class="input-text full-width" value="" placeholder="First Name" />
}
Upvotes: 2
Reputation: 13488
Try this:
@for (int j = 1; j <= numberOfTravelers; j++)
{
<input type="text" name='@("FirstNameEN"+j)' class="input-text full-width" value="" placeholder="First Name" />
}
Upvotes: 1