bramwell2010
bramwell2010

Reputation: 175

Form name value based on c# variable

Is there any way to create the name variable in an input text field with a c# variable in it?

So something like:

<input type="text" name="Status + @i" value="" />

I tried a few different combinations:

name="'Status' + '@i'"
name = "Status" + @i

but none of them worked after submitting.

Upvotes: 0

Views: 910

Answers (3)

Armen
Armen

Reputation: 1093

<input type="text" name="Status_@i" value="" />

Upvotes: 0

revlayle
revlayle

Reputation: 71

Also

@('Status' + i.ToString())

OR

<input type="text" name="Status@(i)" value="" />

I think works too

should work too, String.Format is more flexible, however.

Upvotes: 0

YD1m
YD1m

Reputation: 5895

Use String.Format() :

name="@String.Format("Status{0}", i)"

or directly

name='Status@i'

Upvotes: 3

Related Questions