I have a loop inside my cshtml file. This loop has a i
variable and I use it to compose a name according to its position in the loop, type txtNome1
, txtNome2
, txtNome3
, and so on.
I need to make the variable be composed with leading zeros so that the name less than 10 looks like this: txtNome01
, txtNome02
, txtNome03
, and so on.
How to do this within the loop in the cshtml
file? My problem is how to use it. See below for part of my for (loop). I need to compose the variables that will complete the name.
string
nm,dia,mes,ano,sexo,numpassaporte,
diavalidade, mesvalidade,
anovalidade, paisemissao = "";
for (int i = 1; i < 3; i++)
{
nm = "txtNome" + i;
dia = "txtDia" + i;
mes = "txtMes" + i;
ano = "txtAno" + i;
sexo = "txtSexo" + i;
numpassaporte = "txtPassaporte" + i;
diavalidade = "txtDiaVal" + i;
mesvalidade = "txtMesVal" + i;
anovalidade = "txtAnoVal" + i;
paisemissao = "txtPaisEmissao" + i;
I have spoken JavaScript, but it can be anything, as long as it is not in the code behind to give more performance to the site.