We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Duplicate selected values in multiselect dropdownlist

Thread ID:

Created:

Updated:

Platform:

Replies:

130660 May 24,2017 04:28 AM Jun 1,2017 08:00 AM ASP.NET MVC 3
loading
Tags: DropDownList
Carsten Buchmann
Asked On May 24, 2017 04:28 AM

Hi,

I got a problem with a multiselect Dropdownlist. I set the datasource with my model and set the datafields value, text and selected. But in the view my selected entries are duplicated. The property "SelectedSpecializationDefinitions" is an empty string array and in the property SpecializaionDefinition you can find the objects (see screenshot "ej.CreateObject....")

What I'm doing wrong? 

Kind regards,
Carsten

     <div class="form-group">
            @Html.LabelFor(model => model.StationaryAsset.SelectedSpecializationDefinitions, htmlAttributes: new { @class = "control-label col-md-4" })
            <div class="col-md-8">
                @(Html.EJ().DropDownListFor(Model => Model.StationaryAsset.SelectedSpecializationDefinitions)
                    .Width("100%")
                    .Datasource(Model.StationaryAsset.SpecializationDefinitions)
                    .DropDownListFields(df =>
                        df.Value("Id")
                        .Text("Description")
                        .Selected("Checked")
                        )
                    .ShowCheckbox(true)
                    .MultiSelectMode(MultiSelectModeTypes.VisualMode))
            </div>

        </div>



Keerthana Rajendran [Syncfusion]
Replied On May 25, 2017 07:15 AM

Hi Carsten, 
 
Based on your code, we have prepared a sample to reproduce the reported issue. Unfortunately, we were unable to reproduce the reported issue at our end. Please refer the below given screenshot:   
 
Duplicated selected values are not found.  
 
Please refer to the below given link for sample 
 
 
If the issue persists ,kindly revert by modifying the above sample to reproduce the issue along with the details of product version which you are using. This will be helpful to analyze further and provide better solution at the earliest 
 
 
Regards, 
Keerthana R. 


Carsten Buchmann
Replied On May 31, 2017 09:19 AM

I found my mistake. The property "Id" must be of type string. But now I'm only getting nothing back in my post method. With your example from https://help.syncfusion.com/aspnetmvc/dropdownlist/stronglytypedhelper I tried to manage it but with no success.Here's your modified example with a post method: https://systmanu-my.sharepoint.com/personal/cbu_symplion_de/_layouts/15/guestaccess.aspx?docid=064e8037737a247aa9ace7587d03bf20e&authkey=AfPn3sM60elE-_rKZxXR4_Y Here you can see that in the HttpPost Index Method the viewModel got no selected items from the dropdownlist.

Keerthana Rajendran [Syncfusion]
Replied On June 1, 2017 08:00 AM

Hi Carsten, 
We checked the reported  issue in the attached sample. When selecting single item in DropDownList the selected value will be returned in DropDownList model and this will not work in case of multiple selection. We suggest you to follow the below work around in your sample to achieve the requirement.  
 
[HttpPost] 
        public ActionResult Index(DropDownListModel model, string[] DropData) 
        { 
            ViewBag.datasource1 = data; 
            DropDownListProperties ddl = new DropDownListProperties(); 
            ddl.DataSource = DropData; 
            ddl.Value = string.Join(",", DropData); 
            DropDownListFields ddf = new DropDownListFields(); 
            ddf.Text = "Description"; 
            //ddf.Value = "id"; <-- leads to duplicated selected values 
            ddf.Value = "Description"; 
            ddf.Id = "id"; 
            ddf.Selected = "Checked"; 
            ddl.DropDownListFields = ddf; 
            ViewData["ddl"] = ddl; 
            return View(model); 
        } 
 
Pass the value of DropDownList in Post method  and join the values using string.Join() and assign this data to DropDownList datasource. 
 
We have modified the sample by including these changes. Please refer to the below given link 
 
 
Regards, 
Keerthana R. 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;