Binding select in view with list in model

86 views Asked by At

I have a Model class

class ItemModel
{
    public List<string> Values { get; set; }
}

And a view

@model List<ItemModel>

@using (Html.BeginForm(null, null, FormMethod.Post))
{
    @Html.ValidationSummary()
    for (var i = 0; i < Model.Count; i++)
    {
            @Html.DropDownListFor(m => m[i].Values, new SelectList(Model[i].Values))
    }
    <input type="submit" value="Save"/>
    }
}

How should the view look like, if I want to get the list values back in model after submitting the form. The values will be edited with js on client side. The selected item is insignificant.

0

There are 0 answers