ASP.NET MVC Dropdown list on change to cause postback without Javascript

17,913

Solution 1

You need JavaScript to automatically post back data. You don't have to write it, but you still need it. You can post without JavaScript (someone pressing a submit button), but not automatically.

I believe what you are thinking of is the AutoPostBack property.

Solution 2

You can achieve the postback effect using jQuery. JavaScript in some form or another is required for automatic postbacks. Even ASP.NET uses JavaScript in the background to implement the AutoPostBack property.

<script type='text/javascript'\> 
  $('#dropDown').change(function () {
    $(this).parents('form').submit();
  });
</script>

Solution 3

Do this:

More here:

How do you submit a dropdownlist in asp.net mvc

Solution 4

Complete script which worked for me

 @Html.DropDownList("Projects", Model.Projects, new { 
 style = "Height: 25px; width: 225px;", 
 onchange = "$(this).parents('form').submit();" })
Share:
17,913
4imble
Author by

4imble

Senior .NET / Full Stack Developer Contact: me(at)4imble.net

Updated on June 08, 2022

Comments

  • 4imble
    4imble almost 2 years

    Is it possible to cause a postback to an action from changing your selection in a dropdown list without using JavaScript?

    I remember when using the ASP.NET Forms dropdown list control, there was a property that when set would cause a postback on change, did this work without JS? - If so, how?

    Many thanks, Kohan.