I want from user to input 5 strings (possible answers for question), so I have these elements in my question view model:

private IEnumerable<string> _possibleAnswers;
        public IEnumerable<string> PossibleAnswers 
        { 
            get
            {
                return _possibleAnswers ?? new List<string>();
            }
            set 
            {
                _possibleAnswers = value;
            }
        }

My partial view looks like this:

@model IEnumerable<string>
@{
    ViewBag.Title = "PossibleAnswers";
}

@foreach (var str in Model)
{
       @Html.EditorFor(m => str, new { @class = "form-control", placeholder = "Odgovor" })
}

But since PossibleAnswers list is empty, none of the edit fields show when I run the application. What do I need to change to display 5 edit fields and post them back correctly to controller?

Related posts

Recent Viewed