Ajax.BeginForm replaces whole page onchange of a dropdownlist

前端 未结 2 413
误落风尘
误落风尘 2020-12-24 08:13

The purpose

I have a simple table listing names (in a partial view), and above it a dropdownlist containing those names. The purpose is to filter th

相关标签:
2条回答
  • 2020-12-24 08:59

    In your dropdown replace:

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

    with:

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

    Also get rid of all MicrosoftAjax*.js scripts. Those are completely legacy and shouldn't be used in ASP.NET MVC 3 and newer applications. They are provided only for compatibility reasons if you are migrating from older versions. jQuery.js and jquery.unobtrusive-ajax.js are enough.

    0 讨论(0)
  • 2020-12-24 09:03

    Not sure if I understand it correctly, but if submit button works OK why not just do this:

    @Html.DropDownList("filterName", new SelectList(ViewBag.Names), "Select a name", new   { onchange = "clickMe('mybuttonId')" })
    

    and write small script

    function clickMe(id) {
      $('#' + id).click() // where id is id of button that should submit the form.
    }
    

    If you do not want the button to display then just hide it. This is a hack and if it doesn't fit your needs we can investigate further.

    0 讨论(0)
提交回复
热议问题