MVC5 Razor html.dropdownlistfor set selected when value is in array
<p>I'm developing an ASP.NET MVC 5 application, with C# and .NET Framework 4.6.1.</p>

<p>I have this <code>View</code>:</p>

<pre><code>@model MyProject.Web.API.Models.AggregationLevelConfViewModel

[...]

@Html.DropDownListFor(m =&gt; m.Configurations[0].HelperCodeType, (SelectList)Model.HelperCodeTypeItems, new { id = "Configurations[0].HelperCodeType" })
</code></pre>

<p>The <code>ViewModel</code> is:</p>

<pre><code>public class AggregationLevelConfViewModel
{
    private readonly List&lt;GenericIdNameType&gt; codeTypes;
    private readonly List&lt;GenericIdNameType&gt; helperCodeTypes;

    public IEnumerable&lt;SelectListItem&gt; CodeTypeItems
    {
        get { return new SelectList(codeTypes, "Id", "Name"); }
    }

    public IEnumerable&lt;SelectListItem&gt; HelperCodeTypeItems
    {
        get { return new SelectList(helperCodeTypes, "Id", "Name"); }
    }

    public int ProductionOrderId { get; set; }

    public string ProductionOrderName { get; set; }

    public IList&lt;Models.AggregationLevelConfiguration&gt; Configurations { get; set; }

    public AggregationLevelConfViewModel()
    {
        // Load CodeTypes to show it as a DropDownList
        byte[] values = (byte[])Enum.GetValues(typeof(CodeTypes));

        codeTypes = new List&lt;GenericIdNameType&gt;();
        helperCodeTypes = new List&lt;GenericIdNameType&gt;();

        for (int i = 0; i &lt; values.Length; i++)
        {
            GenericIdNameType cType = new GenericIdNameType()
            {
                Id = values[i].ToString(),
                Name = EnumHelper.GetDescription((CodeTypes)values[i])
            };

            if (((CodeTypes)values[i]) != CodeTypes.NotUsed)
                codeTypes.Add(cType);

            helperCodeTypes.Add(cType);
        }
    }
}
</code></pre>

<p>And <code>Models.AggregationLevelConfiguration</code> is:</p>

<pre><code>public class AggregationLevelConfiguration
{
    public byte AggregationLevelConfigurationId { get; set; }
    public int ProductionOrderId { get; set; }
    public string Name { get; set; }
    public byte CodeType { get; set; }
    public byte HelperCodeType { get; set; }
    public int PkgRatio { get; set; }
    public int RemainingCodes { get; set; }
}
</code></pre>

<p>I need to set selected value in these properties:</p>

<pre><code>public IEnumerable&lt;SelectListItem&gt; CodeTypeItems
{
    get { return new SelectList(codeTypes, "Id", "Name"); }
}

public IEnumerable&lt;SelectListItem&gt; HelperCodeTypeItems
{
    get { return new SelectList(helperCodeTypes, "Id", "Name"); }
}
</code></pre>

<p>But I can't set it in <code>new SelectList(codeTypes, "Id", "Name");</code> or <code>new SelectList(helperCodeTypes, "Id", "Name");</code> because the selected value are in <code>Configurations</code> array: fields <code>AggregationLevelConfiguration.CodeType</code> and <code>AggregationLevelConfiguration.HelperCodeType</code>.</p>

<p>I think I have to set selected value in the View, but I don't know how to do it.</p>

<p>How can I set the selected values?</p>