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

前端 未结 7 1801
自闭症患者
自闭症患者 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:54

    I had the same problem too. I had several dropdown lists in partial views so they could refresh independently, but setting the "onchange" attribute kept refreshing the entire page.

    I noticed that "this.form.submit()" always referred to the main form, outside the partial view. So instead I added a submit button inside the AJAX form and referred to that:

    <%=Html.DropDownList("data", ViewData["data"] as SelectList
    , new { onchange = "$(\"#button" + Model.IdIndex + "\").click();" })%>
    
    
    

    My "Model.IdIdex" is just a variable to access different controls in the same page. Hope it helps.

提交回复
热议问题