Hey I've been trying to get the value from a dropdownlist, and cant seem to get it working. Am I doing something wrong.
The dropdown displays normally and everything and i map the event fine, but once it fires i get this javascript error when it tries to get the value:
"Uncaught TypeError: Cannot call method 'value' of undefined" Here is my code:
@Html.LabelFor(m => m.Country)
@(Html.Kendo().DropDownListFor(m => m.Country)
.Name("CountriesDropDown")
.DataTextField("Name")
.DataValueField("CountryID")
.DataSource(source =>
{
source.Read(read =>
{
read.Url("/WebUI/API/Countries/");
});
})
.Events(e => e.Change("CountryChange"))
)
<script type="text/javascript">
var CountriesList = $("#CountriesDropDown").data("kendoDropDownList");
function CountryChange()
{
alert(CountriesList.value());
}
</script>
Thanks in advance!
The dropdown displays normally and everything and i map the event fine, but once it fires i get this javascript error when it tries to get the value:
"Uncaught TypeError: Cannot call method 'value' of undefined" Here is my code:
@Html.LabelFor(m => m.Country)
@(Html.Kendo().DropDownListFor(m => m.Country)
.Name("CountriesDropDown")
.DataTextField("Name")
.DataValueField("CountryID")
.DataSource(source =>
{
source.Read(read =>
{
read.Url("/WebUI/API/Countries/");
});
})
.Events(e => e.Change("CountryChange"))
)
<script type="text/javascript">
var CountriesList = $("#CountriesDropDown").data("kendoDropDownList");
function CountryChange()
{
alert(CountriesList.value());
}
</script>
Thanks in advance!
UPDATE:
I noticed one more strange thing, I use DropDownListFor to map the dropdown list to my model. On the server side, if I have a Name for this DropDownList defined ( .Name("CountriesDropDown") ) i doesnt catch the value of the dropdown list if I remove the name it works fine. Is this a bug, or am I missing something?
I noticed one more strange thing, I use DropDownListFor to map the dropdown list to my model. On the server side, if I have a Name for this DropDownList defined ( .Name("CountriesDropDown") ) i doesnt catch the value of the dropdown list if I remove the name it works fine. Is this a bug, or am I missing something?