开发者

Form with many checkboxes, how to get a list of id's?

I have a form, each row has a checkbox on it like:

<input type=checkbox id="cb-<%= o.ID %>" name="mycheckboxes" />

When the form is posted to an a开发者_运维技巧ction, how can I get a list of the checked checkbox's id values?

Is it possible since they all have the same name?


Store the value in the value attribute of the checkbox:

<input type="checkbox" value="<%= o.ID %>" name="mycheckboxes" />

In your action, tell ASP.NET MVC to look for an int[] with the name "mycheckboxes":

public ActionResult MyAction(int[] mycheckboxes)
{
   // do stuff here
}


I believe you are looking in javascript then Yes, use document.getElementsByName('') to get the list of all the checkbox and iterate thru them in the loop to find if its checked and get the ID.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜