Kendo-UI DropDownListFor - selected index - asp.net-mvc

I need to change standard dropdown list to the one from kendo and and I've got a problem with getting appropriate selected value.
This code gives me a dropdown list with correct values, but doesn't give selected value (first one is selected).
#(Html.Kendo().DropDownListFor(m => m.CountryName)
.BindTo(Model.AllCountries)
.OptionLabel("-- Select country --")
)
Inside span (generated by kendo) with this dropdown I found input (type = text) with all values as options, and this input has correct value.
How to display this value in my kendo dropdown?
Thanks

Have you tried setting the name of the DropDownList equal to the name of the property in your model? The Kendo Documentation suggests that "if widget's name is different than the Model's property then the ModelBinder will not be able to update the model."

Related

How to handle default dropdown values using jquery ajax in mvc3?

Based on selection of first dropdown i am binding another drop down values based on first dropdownid value.My question is i given default first dropdown value as "select" but there is no id value for that in second dropdown to get the values.if user selectes "select" in frist dropdown i need to load all values in second dropdown.please tell me how to acheive this?
If you given default first dropdown value as "select" means, at that time disable the second drop down value. If 'country' value equal to 'select' means, at that time disable the 'state drop down'.When we click that country 'select' at that time also call that disable drop down function.
For example HTML view page, country drop down displayed. From that you will get country ID.
$countryID=> From your MVC code you have pass default country ID (default ID)
$countrySelected=$this->getCountryFromName(trim($countryID']));
if ($countrySelected!= ''){
$sVal=$this->getStateList($countrySelected);
$newStateList=array('0'=>'State');
$newStateList+=$this->formatDropdownArray($sVal,'STATE_ID','NAME');
$stateSelected='State';
echo CHtml::dropDownList('STATE_IDD',$stateSelected,$newStateList,array('tabindex'=>9));
}else{
$stateSelected=$defaultState;
echo CHtml::dropDownList('STATE_IDD',$stateSelected,$stateList,array('tabindex'=>9));
}

how to populate values in listbox based on value entered in textbox in BIRT?

I want to populate values in a list box based on a value entered in textbox. It cant be aceived through cascading paramters as all parameters in Cascading parameters are List Boxes. But my requirement is to populate values inside a ListBox based on the value entered inside a textbox. Please help.
Cascading parameter is the only way to define a dependency between two parameters. As you can see, the birt web viewer displays a textbox just below each combobox, and a radio button to select if we fill each list parameter from the combobox or the textbox:
I know some users had exactly the same requirement, and have successfully modified "ComboBoxParametersFragments.jsp" to display only the textbox when it is needed. For example we can use a specific prefix in the parameter name, or a user property, so that we can decide in the JSP if we hide the combobox or not.

Specify DropDownList options in MVC 3 Razor

I'd like to know if it is possible to assign a default value for a Dropdownlist while restricting User to select that default value from its option list.
Example :
#Html.DropDownListFor(m => m.Something, new SelectList(Model.TheList), "--DefaultValue--", new { name="SomethingName", id="SomethingID", style="width:150px;"})
Let's suppose TheList contains {"1","2","3"}.
When User clicks the DropDownList, he will find "--DefaultValue--" displayed as initial value, and also find it as one of the options available to be selected.
Is it possible only to have 1,2, and 3 alone as the options without "--DefaultValue--" ?
The only way is to set selected value in DropDown. --Default value-- represents null in selected value
Try this:
#Html.DropDownListFor(m => m.Something, new SelectList(Model.TheList),new { name="SomethingName", id="SomethingID", style="width:150px;"})

MVC - DropDownList wrong option selected when value from model is null

I have two DropDownLists in form, both displaying list of regions. First is required, second not, stored as null in db.
When I open the page for edit and first dropdownlist is ie. Region 2, and the second is null, the first option "< not specified >" should be selected in second dropdownlist, but the same option as in first dropdownlist is selected.
When I check for null in controller and set the property to value, which is not in the dropdownlist, ie. -1, it selects corrects first option "< not specified >".
Is there a way to recieve the first option selected, when the model value for this dropdown is null ?
kubiix

how can get previously selected value in dropdown list in edit page

I am using viewbag to put data in dropdownlist. In my edit page, I want to have selected value as the default value in my dropdown list.
I am sending dropdownlist from the controller class as follows:-
ViewBag.WareHouseId = new SelectList(db.WareHouse, "ID","Description");
my view code for dropdownlist is:-
#Html.DropDownList("WareHouseID","SELECT")
what should I add in the above line to show previously selected value before changing the value of drop downlist.?
Pass the model value to the optionLabel parameter:
#Html.DropDownList("WareHouseID", "SELECT", Model.WareHouseID)

Resources