Remove space in the name of an input

Asked

Viewed 36 times

0

It’s like, I’m doing a foreach this way .

int count = 1;
@foreach (var item in Model)
    {
        <input name="itemId_@count" value="@item.ProdutoId" type="hidden">

        count++;
    }

The problem is that in processing the underline is processed together, and I needed it not to be processed if I do it this way.

@foreach (var item in Model)
{
    <input name="itemId@count" value="@item.ProdutoId" type="hidden">

    count++;
}

@Count is not recognized.

I need an alternative to be able to reference @Count without using spaces or characters. Or some little space-clearing script, but I have no idea if that’s possible.

1 answer

0

You need to use keys () by the arroba @.

@{
    int count = 1;
    foreach (var item in Model})
    {
        <input name="itemId@(count)" value="@item.ProdutoId" type="hidden">

        count++;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.