Friday, October 19, 2012

ASP .NET MVC 3 RAZOR Dropdownlist Ajax AutoPostback

ASP .NET MVC 3 RAZOR Dropdownlist Ajax AutoPostback
Wow, what a mouthful. I am a bit sick of StackOverflow's policy for today.
So here it is : I want a dropdown list to cause submission of my Ajax form to retrieve some JSON formatted results for use elsewhere in the page.
  @{using (Ajax.BeginForm("SelectState",
           "Census", 
           new AjaxOptions() { 
             HttpMethod = "Post", 
             OnSuccess = "SelectComplete",
             OnFailure = "Fail" })) 
    {
                         
      @Html.DropDownList("ddlState", 
                         (SelectList)ViewData["StateList"],
                         new { onchange = "$('#bSetName').click()" });  
                                                    
      <input id="bSetName" name="bSetName" 
             style="display: block;" type="submit" />
                                                                                                    
    }
   }
 
I hate this, but it works. Any better ideas?