Null ThemedChoiceListFor make Model Object invalid.

Jun 13, 2011 at 7:24 PM
Edited Jun 13, 2011 at 7:24 PM

Hi everybody,

I am facing a problem in using the ThemedChoiceList Control. The issue is when there is no object in the selected side of the control i.e. List<int>Property =null in Controller's Post Action Method, the control marks my model object invalid.

Model code:

    public partial class Campaign : IDataErrorInfo
        private Dictionary<string, string> _errors = new Dictionary<string, string>();

        #region Properties

        [DisplayName("Select Products")]
        public List<int> SelectedProducts { get; set; }

        [DisplayName("Select Countries")]
        public List<int> SelectedCountries { get; set; }

        [DisplayName("Select Lead Fields")]
        public List<int> SelectedCampaignLeadFields { get; set; }


UI code:

 @Html.ThemedChoiceListFor(m => m.SelectedProducts,
                                new CommonList().GetProductsByClientID(((ClientUser)Session["ClientUser"]).ClientID),
                                (t => t.ProductID),
                                (t => t.Name),
                                m => new


Controller Code :

        public ActionResult Create(Model.Campaign model)

                    if (!ModelState.IsValid)
                    { return View(model); }



The validation fails as it makes it invalid. But if I select something in the list. It works fine...!!

Thanks for your help!!

Jun 14, 2011 at 1:29 PM

Hi @munishsehgal the behaviour you have noticed is due to a bug of the in the 1.1 RC version, that has been already removed in the upcoming version that will be realeased tomorrow or after tomorrow. Sorry for the inconvenience.