Cant get the value

2 posts, 0 answers
  1. Dennis
    Dennis avatar
    30 posts
    Member since:
    Aug 2012

    Posted 27 Jun 2012 Link to this post

    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!

    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?




  2. Dennis
    Dennis avatar
    30 posts
    Member since:
    Aug 2012

    Posted 27 Jun 2012 Link to this post

    I got past this using it like this:

    $("#CountriesDropDown").data("kendoDropDownList").value();
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top