How do you submit a dropdownlist in asp.net mvc from an Ajax form

前端 未结 7 1782
自闭症患者
自闭症患者 2020-12-25 13:12

How do you submit from a dropdownlist \"onchange\" event from inside of an ajax form?

According to the following question: How do you submit a dropdownlist in asp.ne

7条回答
  •  自闭症患者
    2020-12-25 13:39

    OK, nearly 2 years later, you probably don't care anymore. Who knows: Maybe others (such as me ;-) do.

    So here's the (extremely simple) solution:

    In your Html.DropDownList(...) call, change

    new { onchange = "this.form.submit()" }
    

    to

    new { onchange = "this.form.onsubmit()" }
    

    Can you spot the difference? ;-)

    The reason is that Ajax.BeginForm() creates a form with an onsubmit() handler to submit the form asynchronously. By calling submit(), you bypass this onsubmit() custom handler. Calling onsubmit() worked for me.

提交回复
热议问题