Search code examples
asp.net-mvchtml-helperautopostback

AutoPostback from Html.Listbox in ASP.NET MVC?


Now, i may very well just be being incredibly thick, but I'm struggling to find how to do autopostback with a Html.Listbox in ASP.NET MVC 1.

What I'm trying to achieve is just a simple if value of ListBox1 is x then the values in ListBox2 are y, if I change the value in ListBox1 to z then I want the values of ListBox2 to change based off of that information.

The information will be pulled from a Database.

I know this is easy to in standard ASP.NET, but I can't see an obvious way to do it with MVC.

Could someone point me in the right direction?

Thanks in advance for any help.


Solution

  • postback and asp mvc are not really compatable, you should look at using jquery, very roughly like...

    $(function() {
        $('#box1').change(function() {
                $.post('/controller/actionThatReturnsAPartialView',
                       { selectedID : $('box1').val()},
                       function(data){
                             $('#box2').html(data);
                       }
                );
         });
     });
    

    MVC, by design cuts out most of the asp.net abstractions like viewstate and postback, it is much more low level.