How to get all ListBox items on submit action
How can I get all ListBox val开发者_运维技巧ues (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.
This code works for me!
<script type="text/javascript">
$(document).ready(function () {
$("#myForm").submit(function (e) {
$("#myList option").prop("selected", "selected");
});
});
</script>
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();
}
精彩评论