This project is read-only.

Problem with DualSelectFor

Aug 15, 2011 at 6:14 PM


I want to implement the SelectFor method. To do so I have a viewmodel that contains 2 lists of ContactSimpleDTO. 1 with the selected (previous selected) and one with the full collection. 

I try to create the DualSelectFor object with:

var x = Html.DualSelectFor(m => m.SelectedContacts, new ChoiceList<ContactSimpleDTO,string,string>(Model.AllContacts, (t => t.PersonId), (t => t.FullName))) ;

But when I run this I get this error:

Compiler Error Message: CS0411: The type arguments for method 'MVCControlsToolkit.Controls.DualSelectHelper.DualSelectFor<TModel,TChoiceItem,TValue,TDisplay>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,System.Collections.Generic.IEnumerable<TValue>>>, MVCControlsToolkit.Core.ChoiceList<TChoiceItem,TValue,TDisplay>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

What could be the problem?



Aug 15, 2011 at 6:41 PM

1) First of all please try to use the ChoiceListHelper class to create the ChoiceList, instead to create it implicitely. If you use the helper you don't need to specify  the all trhee geberics because the compiler is able to infer them automatically. For the use of the ChoiceListHelper, see here:


2) Pay attention the dual select box works like a DropDown: the List of selected items must contain just the id (in your case PersonId) of the selected items, not the whole entities. I must look like new List<int>{1, 4, 3, 2} if the id are numbers.

Aug 15, 2011 at 7:10 PM

I changed to the ChoiseListHelper, but still have the same problem. This is what I have

var x = Html.DualSelectFor(m => m.SelectedContacts,ChoiceListHelper.Create(Model.AllContacts, (t => t.PersonId), (t => t.FullName)));

    public class TestDayDTO{
        public TestDayRowDTO TestDayRowDTO { get; set; }
        public List AllContacts { get; set; }
        public List SelectedContacts { get; set; }


    public class ContactSimpleDTO
        public string PersonId { get; set; }
        public string FullName { get; set; }

Aug 15, 2011 at 8:04 PM
Edited Aug 15, 2011 at 8:36 PM

sorry, I missed the part two. I now have only a list with strings in my selected items. It does not crash on anymore, but it doesnt show a list.. tried the 

Html.CheckBoxListFor(m => m.SelectedContacts, ChoiceListHelper.Create(Model.AllContacts, (t => t.PersonId), (t => t.FullName)));
edit, solved it. It's my first project with razor and did something wrong in razor..
instead of @Html.Checkbox....