Hi Everyone,
I have a question regarding the ASP.NET MVC Dropdownlist.
I load my DDL with data from the controller like this.
public JsonResult GetCountries(){ SelectList list = null; ServiceSession.CreateService<MemberService>((Service) => { var country = Service.GetCountryCodes(); list = new SelectList(country, "Id", "Name", country.Where(e=>e.Name== "Danmark").First()); }); return Json(list, JsonRequestBehavior.AllowGet);}
@(Html.Kendo().DropDownListFor(m => m.CountryCode) .DataTextField("Text").DataValueField("Value").SelectedIndex(185). AutoBind(true).DataSource(dataSource => dataSource.Read(read => { read.Action("GetCountries", "Member"); })))Everything is fine, but how can I set the selectedIndex by the text and not the ID in the list?
I can't be sure that Denmark is always number 185.