title: cascading dropdown not working
body: <p>i am trying to use cascading dropdown list in mvc. some how it is working but having some problem. actually when first view is rendered i have a dropdown Account Type on the basis of this dropdown i have to populate the group dropdown. but when the first dropdown is rendered it has to option realtor and sponsor by default realtor is the first option selected and then all the group who are associated with it sholud be rendered. but can not able to get the value at the very first time. what is the issue can anyone suggest me .</p>
  
  <p>here is my code</p>
  
  <pre><code>public class ViewModel
  {
   [Required]
          public SelectList AccountType { get; set; }
          public string SelectedAccountType { get; set; }
          public IEnumerable&lt;SelectListItem&gt; Group { get; set; }
          public string SelectedGroup { get; set; }
  }
  
  
  [HttpGet]
          public ActionResult Index(ViewModel viewModel)
          {  
  
  
  
              List&lt;SelectListItem&gt; groups = sDbContext.Groups
                      .Where(o =&gt; o.GroupId &gt; 1 &amp;&amp; o.Deleted == false &amp;&amp; o.AccountSubId == 1).OrderBy(uu =&gt; uu.GroupName)
                      .Select(o =&gt; new SelectListItem()
                      {
                          Value = o.GroupId.ToString(),
                          Text = o.GroupName
                      }).ToList();
              groups.Insert(0, new SelectListItem() { Value = "0", Text = "All" });
              viewModel.Group = groups;
              viewModel.AccountType = new SelectList(sDbContext.AccountTypes.Where(o =&gt; o.AccountTypeId != 0), "AccountTypeId", "AccountName");                          
              reportService.GetReportsListGrid();
              return View(viewModel);           
      }
  </code></pre>
  
  <p>view :</p>
  
  <pre><code>@model App1.ViewModels.ViewModel
  @{
      List&lt;SelectListItem&gt; list = new List&lt;SelectListItem&gt;();   
  }
  @using (Html.BeginForm("Index", "routee", FormMethod.Post, new { @id = "appForm" }))
  {
   Account Type
                                  @Html.DropDownListFor(m =&gt; m.SelectedAccountType, (IEnumerable&lt;SelectListItem&gt;)Model.AccountType, new { @class = "form-control" })
   @Html.DropDownListFor(model =&gt; model.SelectedGroup, list, new { @class = "form-control" })
                                  @Html.ValidationMessageFor(model =&gt; model.SelectedGroup)
  
  }
  </code></pre>
  
  <p>and here is my script..</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   $('#SelectedAccountType').change(function () {
          OnAccountTypeChange();
      });
  
      function OnAccountTypeChange() {
          var id = $("#SelectedAccountType :selected").val();
          var groupId = $('#SelectedGroup').val();
          if (id != "") {
              alert(id);
              $.ajax({
                  type: "GET",
                  contentType: "application/json; charset=utf-8",
                  url: '@Url.Action("GetGroupsByAccountSubTypeId", "Common", new { area = "" })',
                  data: { "AccountSubId": id },
                  dataType: "json",
                  beforeSend: function () {
                      //alert(id);
                  },
                  success: function (data) {
                      var items = "&lt;option value='0' selected='selected'&gt;-All-&lt;/option&gt;";
                      $.each(data, function (i, groups) {
                          items += "&lt;option value='" + groups.Value + "'&gt;" + groups.Text + "&lt;/option&gt;";
                      });
                      $('#SelectedGroup').html(items);
                      if (groupId != undefined || groupId != null || groupId != "")
                          $('#SelectedGroup').val(groupId);
                  },
                  error: function (result) {
                      console.log('Service call failed: ' + result.status + ' Type :' + result.statusText);
                  },
                  complete: function () {
                      $('#SelectedGroup').prop('disabled', false);
                  }
              });
          }
          else {
              $('#SelectedGroup').html(items);
          }
      }
  &lt;/script&gt;
  </code></pre>