2

In an MVC appllication, we have a dropdownlist on a form. I am using Ajax.Beginform() to post back data.

Is there a way to use dropdown selected index changed event to postback form data using Ajax.Beginform(). Any suggestions please ?

  @using (Ajax.BeginForm("_EditMailToData", "Work", new AjaxOptions() { UpdateTargetId = "MailToFieldSet", HttpMethod = "POST" }, new { @id = "mailTo" }))
        {
            <fieldset id="MailToFieldSet">
             <h4 style="color: black">Mail To:</h4>

                <table style="width: 100%; background-color: #FFFFFF;" border="0" align="left">
   <tr>
    <td align="left" style="border: solid 0px;" nowrap="nowrap">
        @Html.LabelFor(m => m.MailToLocation)
    </td>
    <td align="left" style="border: solid 0px #00457C;" nowrap="nowrap">
       @Html.DropDownListFor(m => m.MailToLocation, Model.Locations)

    </td>
</tr> 
<tr>
    <td align="left" style="border: solid 0px;" nowrap="nowrap">
        @Html.LabelFor(m => m.MailToName)
    </td>
    <td align="left" style="border: solid 0px #00457C;" nowrap="nowrap">
        @Html.TextBox("txtmailToName", (string)Model.MailToName)
    </td>
</tr>
tereško
  • 58,060
  • 25
  • 98
  • 150
gurrawar
  • 363
  • 2
  • 8
  • 17
  • 1
    Okay, I deleted my incorrect answer, I goofed and overlooked the Ajax form part of the question. Check out this answer, I think it will do what you need: http://stackoverflow.com/questions/7243042/mvc3-razor-ajax-form-submit. Basically, use javascript to spoof a click on the submit button, and ASP.Net will do the ajax post as it would if you had clicked the button. – Gromer Jul 26 '12 at 21:21

1 Answers1

0

You can use the change event if you are using jquery

$("#MailToLocation").change(function(){
  $("#mailTo").submit();
})
VJAI
  • 32,167
  • 23
  • 102
  • 164