Hello,
My MVC project uses a (javascript) dropDownList with Json data source. When loading the view I would like to assign the selectedItemIndex if a previous selection was made, or have the list be empty (null selected value) if no selection has been made. Something like this:
@{
int index = -1;
if(Model.previouslySelectedIndex > -1){
index = Model.previouslySelectedIndex;
}
}
<script>
$('#ddl').ejdropdownlist({
dataSource: myJson,
selectedItemIndex: Number(@index)
});
</script>
It appears that using -1 for the selectedItemIndex does not work; the selectedItemIndex appears to be set to 0 instead. Using null throws an error.
I also tried using the MVC wrapper and it appears that you can successfully assign the value of -1. However, for other reasons I need to use the plain javascript controls.
Can anyone suggest the best way to accomplish this?
thank you,
Randy