开发者

how to get an collection of ids int[] in post action (selected checkboxes)

开发者 https://www.devze.com 2022-12-27 23:29 出处:网络
I need to get in an action method the values from the selected checkboxes on a form how would you do that ? (or probably get them all and see who was selected)

I need to get in an action method the values from the selected checkboxes on a form how would you do that ? (or probably get them all and see who was selected)

public ActionResult (int[] ids)
开发者_运维问答

...

<input type="checkbox" value = "1" />
<input type="checkbox" value = "2" />
<input type="checkbox" value = "3" />
<input type="checkbox" value = "4" />

<%=Html.Submit(); %>


You could try giving the checkboxes a name (ids):

<input type="checkbox" name="ids" value="1" />
<input type="checkbox" name="ids" value="2" />
<input type="checkbox" name="ids" value="3" />
<input type="checkbox" name="ids" value="4" />

Should work with:

public ActionResult Index(int[] ids) { ... }
0

精彩评论

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