Search code examples
javascriptasp.net-mvcdom-eventshtml-helper

Html.Dropdown list events in MVC


Can anyone please tell me about -

How can I handle Html.DropDown control's events in MVC View?
Can I handle it using scripts?
And how to know about the selected item?


Solution

  • If you use jquery you can handle events something like this:

    $("#IdOfYourSelectList").change(function() {
        var value = $(this).val();
    });
    

    This creates a handler for the change event. If you want to bind a handler to some other event you just replace change with whatever event you want to handle.

    The same goes for any html element.