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:

[MetadataType(typeof(CampaignMetaData))]
    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; }

        #endregion

UI code:

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

                                }),
                                "Dualselect")

Controller Code :

 [HttpPost]
        public ActionResult Create(Model.Campaign model)
        {       

            try
            {               
                    //Validation
                    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!!

Coordinator
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.

 

Francesco