I want to create a listbox which should be blank initially. But I getting error

System.InvalidOperationException: 'There is no ViewData item of type >>'IEnumerable' that has the key 'rightSelectednumbers'.'

I have not written any controller code for this. Initially, I just want to create it. Anyone please guide me where I am going wrong?


public class NumberClass
       public IEnumerable<SelectListItem> rightnumbers { get; set; }
       public IEnumerable<int> rightSelectednumbers { get; set; }


Please have a look View

  <div class="col-md-6" style="font-family:Arial">
          @Html.ListBoxFor(m => m.rightSelectednumbers, Model.rightnumbers, new { @class = "listBox" })
     <input type="submit" value="move right" />   

1 Answers

Indrit Kello On

Try it this way:

<div class="col-md-6" style="font-family:Arial">
      @Html.ListBoxFor(m => m.rightnumbers, new SelectList(Model.rightnumbers, "Value", "Text", Model.rightSelectednumbers), new { @class = "listBox" })
 <input type="submit" value="move right"/>