checkboxes and radio buttons in MVC FormCollection

给你一囗甜甜゛ 提交于 2019-12-11 08:35:08

问题


I did some searching for determining which radio button is selected and if checkboxes are checked or not just using the FormCollection that is being passed to my Action method.

For reasons I won't go into here, I can't use Html helpers so the auto adding of hidden fields is out for me. I did find someone that suggested using GetValue() on the collection object to determine which radio button is selected, but I can't seem to make that work as it is looking for a ValueProvider and I"m not sure where to put that in.

Basically I just want to be able to determine which radio button is clicked and if a checkbox is checked or not with a form collection....why is that so hard?

Can anyone point me in the right directon please?


回答1:


Been a while since I have looked at this but could it have something to do with check boxes only being submitted if they are checked.

As in if it is submitted its checked.

Iterate through the items in the form if the name of your check box appears its been submitted.




回答2:


I ended up serializing my post array and the radio buttons and checkboxes just worked.



来源:https://stackoverflow.com/questions/7397238/checkboxes-and-radio-buttons-in-mvc-formcollection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!