Razor - @Html.Dropdownlist with dynamic name

Asked

Viewed 298 times

0

I would like to concatenate the ID I get from @Model in the property string name of the Dropdownlist, because I would like to treat them dynamically.

I try to do @Html.Dropdownlist("Name" + @Model.Id) and it doesn’t work.

How could I do?

1 answer

2

Do it in your Model:

public string ConcatenarNome 
    {
        get
        {
            return string.Format("Nome{1}", Id);
        }
    }

And then on View:

@Html.DropDownList(@Model.ConcatenarNome) 

Browser other questions tagged

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