How do we go about selecting the value of a server-bound DropDownListFor() in an edit form? Example:
ViewBag.Countries contains a List<Country>. Country object has a CountryCode and CountryName (strings). The model I'm passing in has a Country field that holds the exact value that's bound to DataValueField("CountryCode"). Nothing gets pre-selected when I open the form (but the list of countries is there). The SelectedIndex() property is useless to me in this instance. Digging through the DropDownListBuilder class the only thing I saw was a Value() method that I'm not sure what it does but giving it the value I want selected doesn't do anything either.
I can't give BindTo() a SelectList() like I used to with the Telerik extensions (unless I'm doing something wrong).
Thanks for any help
@(Html.Kendo().DropDownListFor(m => m.Country) .BindTo(ViewBag.Countries) .DataValueField("CountryCode") .DataTextField("CountryName") .OptionLabel("Select Country"))
ViewBag.Countries contains a List<Country>. Country object has a CountryCode and CountryName (strings). The model I'm passing in has a Country field that holds the exact value that's bound to DataValueField("CountryCode"). Nothing gets pre-selected when I open the form (but the list of countries is there). The SelectedIndex() property is useless to me in this instance. Digging through the DropDownListBuilder class the only thing I saw was a Value() method that I'm not sure what it does but giving it the value I want selected doesn't do anything either.
I can't give BindTo() a SelectList() like I used to with the Telerik extensions (unless I'm doing something wrong).
Thanks for any help