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?

Class

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

View

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" />   
  </div>
}

1 Answers

2
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"/>