This is a migrated thread and some comments may be shown as answers.

How to set the Combo box Value

2 Answers 981 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Vikas
Top achievements
Rank 1
Vikas asked on 19 Jul 2012, 06:34 PM
Hi,

I'm new to Kendo controls. We are replacing the existing MVC controls with Kendo Controls. 

The existing MVC controls looks like below
 @Html.DropDownListFor(model => model.value, new SelectList(ViewBag.list, "id", "label"))

I can able to load the data but not able to set the value like above. Please suggest to set the value. Below is my Kendo control. It has the Value property but doesn't allow model values in it.

    @(Html.Kendo().ComboBox()
                            .Name("ComboBox")
                            .DataTextField("label")
                            .DataValueField("id")
                            .BindTo(@ViewBag.list
    )

2 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 24 Jul 2012, 06:55 AM
Hello Vikas,

 
I will suggest you use the ComboBoxFor, as it provides the same functionality as the Html.DropDownListFor:

@(Html.Kendo().ComboBoxFor(model => model.value)
                            .DataTextField("label")
                            .DataValueField("id")
                            .BindTo(@ViewBag.list
    )
All the best,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Marius
Top achievements
Rank 1
answered on 29 Aug 2012, 08:20 AM
@(Html.Kendo().ComboBoxFor(model => model.GeoGroupCountryId)
                            .DataTextField("Name")
                            .DataValueField("GeoGroupId")
                            .BindTo(@ViewBag.list)
    )

//if you have problem whit circular reference...
//Controller
 ViewBag.list= geocountry.Select(g => new { Name = g.GeoGroup.Name, GeoGroupId = g.GeoGroupId });

///
                                    @( Html.Kendo().ComboBoxFor(model => model.GeoGroupCountryId)
                                .Name("GeoGroupCountryId")
                                .Placeholder("All Countries")
                                .DataTextField("Name")
                                .DataValueField("GeoGroupId")
                                .HtmlAttributes(new { style = "width: 200px;" })
                                .DataSource(source => { source.Read(read => {      read.Action("GetGeoGroupCountry", "GeoGroupPostalCode"); }).ServerFiltering(true); })
                                .AutoBind(true)
                            )
//Controller
        public JsonResult GetGeoGroupCountry()
        {
            var geocountry = _geoGroupService.GetAll<GeoGroupCountry>();
            return Json(geocountry.Select(g => new { Name = g.GeoGroup.Name, GeoGroupId = g.GeoGroupId }), JsonRequestBehavior.AllowGet);
        }
Tags
ComboBox
Asked by
Vikas
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Marius
Top achievements
Rank 1
Share this question
or