I'm trying to set up an input select multiple and leave checked the options that are already present in a certain list.
I'm a beginner in C # so the logic of what I need would be something like this: (Note that I'm using Razor)
Sorry for the answer. I transcribed the wrong code. Correct now:
foreach (var cc in Model.DdlCentroCusto)
{
if (listaCentrosDeCustoEquipe[].CodCentroCusto == cc.Value)
{
<option value="@cc.Value" selected="selected">@cc.Text</option>
}
else
{
<option value="@cc.Value">@cc.Text</option>
}
}
This does not work because I did not specify the index of the item, and can be multiple items. I have already seen some code where related to lists, vi tb that for list there is a Contains option (only I need to go in the specific field and pick up the string and it asks for the type of the object), but I do not know which one to use and I do not know how to use.
I do not think it's difficult, so help will be very welcome.