开发者

How do I implement a checkbox list in ASP.NET MVC?

开发者 https://www.devze.com 2022-12-25 11:53 出处:网络
Just moved f开发者_运维技巧rom WebForms to MVC and replacing various userinterfaces. Not sure how the WebForms CheckListBox is implemented, is there a jQuery plugin or a basic example of this somewher

Just moved f开发者_运维技巧rom WebForms to MVC and replacing various userinterfaces. Not sure how the WebForms CheckListBox is implemented, is there a jQuery plugin or a basic example of this somewhere?


Depending on your need for jQuery, a template similar to this is what I routinely use. (You should be able to wire up jQuery events to this; I'm keeping this to a basic template for now.)

<div class="checkBoxList"><!-- This class usually defines a max-height and overflow -->
    <% foreach (MyObject o in Model.MyObjects) { %>
        <input type="checkbox" name="myObjectSelections" 
            value="<%=o.Value%>" /><br />
        <%=o.Text%>
    <% } %>
</div>

(I may refine this answer in a couple hours once I'm at work and see my real code for this, but it should get you started.)

Your action method for this will take an array of bools for the myObjectSelections argument.

0

精彩评论

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