How to get all ListBox items to submit an action

How can I get all the ListBox values ​​(and not just the selected items) after submitin the project asp.net MVC2?

I use Ajax forms like Ajax.BeginForm("ActionName", new...).

I already tried to select all elements in the event OnBeginfor Ajax parameters, but not all ListBox elements are sent to the controller.

+3
source share
2 answers

That was my decision.

HTML:

<input type="submit" value="Save Changes" onmouseover="SelectAllItems()" />

JavaScript:

function SelectAllItems() {
    $("#UnlinkedProp").each(function() { 
        $("#UnlinkedProp option").attr("selected", "selected"); 
    }); 

    $("#LinkedProp").each(function() { 
        $("#LinkedProp option").attr("selected", "selected"); 
    }); 

    $("#UnlinkedProp").focus(); 

    $("#LinkedProp").focus();
}
0
source

This code works for me!

<script type="text/javascript">
$(document).ready(function () {

    $("#myForm").submit(function (e) {

        $("#myList option").prop("selected", "selected");

    });
}); 
</script>
+2
source

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


All Articles