开发者

How to get all ListBox items on submit action

开发者 https://www.devze.com 2022-12-25 21:18 出处:网络
How can I get all ListBox val开发者_运维技巧ues (not just the selected items) upon submit in an asp.net MVC2 project?

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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号