How can I get HTML DropDownList to send a message?

I am creating a custom pagination mechanism and I have a drop-down list for resizing the page. The page size is presented in my view model. Obviously, I can change the value and run the search again to get the corresponding results.

But is there a way to make DropDownListFor post back when changing the selected value?

+3
source share
2 answers

In fact, I wrote a little javascript to run this behavior:

$(document).ready(function () {
    $('form').find('select.auto-post').change(function () {
        $(this).parents('form').submit();
    });
});

, . , POST HTTP . GET. , .

UPDATE:

jquery :

Html.DropDownListFor(expression, items, new { @class = "auto-post" })
+7

HtmlATtributes "onchange();" .

<%: Html.DropDownListFor(model => model.ProductName, listobj,
                               new { onchange = 'submit()'; }) %>

, .

+10

Source: https://habr.com/ru/post/1786707/


All Articles