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. Image for the cookie policy date

Can not get selected value in dropdownlist with checkbox

Hi,

I've a dropdown list with checkBox, similar at this

Class:

public partial class TipoOS
    {
        public TipoOS()
        {
            CodigoOS = new HashSet<CodigoOS>();
            SubtipoOS = new HashSet<SubtipoOS>();
        }

        public int ID { get; set; }

        [Required]
        [StringLength(150)]
        public string Nombre { get; set; }

        [StringLength(250)]
        public string Descripcion { get; set; }

        public virtual ICollection<CodigoOS> CodigoOS { get; set; }

        public virtual ICollection<SubtipoOS> SubtipoOS { get; set; }
    }

View:
@using (Html.BeginForm("CrearInformes","InformeDiario"))
{              
                <div class="col-md-2">
                    @Html.EJ().DatePicker("FechaInforme").DateFormat("dd/MM/yyyy").Value("17/07/2015").Locale("es-ES")
                </div>
                <div class="col-md-2">
                    @Html.EJ().DropDownList("TipoOperacion").Datasource((IEnumerable<EntitiesInforme.Informe.TipoOS>)ViewBag.DSTiposOperacion).DropDownListFields(ddl => ddl.ID("ID").Text("Nombre").Value("ID")).ShowCheckbox(true)
                </div>               
                <div class="col-md-2">
                    <button type="submit" class="btn btn-default">Generar Informe</button>
                </div>
}

My controller:

 public ActionResult CrearInformes(DateTime? fechaInforme, List<object> tipoOperacion)
{          
            return View();
}



In list "tipoOperacion", I get the Name of selected values, not the ID.

What is wrong?

Thanks

1 Reply

SN Sasikala Nagarajan Syncfusion Team September 3, 2015 11:54 AM UTC

HiManolo,

Thanks for contacting Syncfusion support.

We have analyzed your query (able to get name in post back not id) and unable to reproduce the reported issue at our end. In form post back, we are able to get the ID of the selected items since we mapped the data source’s empidfield to dropdown list value fields. Please refer to the below sample prepared based on the provided code.

Sample: http://www.syncfusion.com/downloads/support/forum/120121/autocomplete_(4)-626656692.zip


In this sample, we have mapped theempidfield of local data source to dropdown list value field (member of DropDownList fields’ property). In form post back we can get the selected item’s id.

Please refer to the below code example:


@Html.EJ().DropDownList("TipoOperacion").Datasource((IEnumerable<object>)ViewBag.datasource).DropDownListFields(ddl => ddl.ID("empid").Text("firstname").Value("empid")).ShowCheckbox(true)


If you are still facing the problem, please revert us with issue reproduced sample that will be helpful for us to analyze further and provide solution.

Regards,

Sasikala Nagarajan


Loader.
Up arrow icon