问题
How can I get all ListBox values (not just the selected items) upon submit
in an asp.net
MVC2
project?
I'm using Ajax forms like Ajax.BeginForm("ActionName", new...)
.
I have already tried to select all the items in the OnBegin
event of the Ajax options but not all of the ListBox items are being POSTed to the controller.
回答1:
This code works for me!
<script type="text/javascript">
$(document).ready(function () {
$("#myForm").submit(function (e) {
$("#myList option").prop("selected", "selected");
});
});
</script>
回答2:
This was my solution.
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();
}
来源:https://stackoverflow.com/questions/2599957/how-to-get-all-listbox-items-on-submit-action