c# - Loop over a FormCollection to get radiobutton SelectedAnswers -
how can values of radio buttons named predicatively questions[i] using form collection?
in form collection
questions[0].objectid questions[0].selectedanswer questions[1].objectid questions[1].selectedanswer questions[2].objectid questions[2].selectedanswer 3 - 13 ... etc... questions[14].objectid questions[14].selectedanswer (a bunch of other stuff)
in controller
[httppost] public actionresult postresults(formcollection form) { list<selectedanswer> selectedanswers = new list<selectedanswer>(); (int = 0; < 15; i++) { //this part not working... selectedanswers.add(new selectedanswer() { questionid = form["questions"][i].objectid; answerid = form["questions"][i].selectedanswer} } //continue other stuff }
my ultimate goal save selected values database.
got working
(int = 0; < 15; i++) { long x = int64.parse(form[string.format("questions[{0}].objectid", i)]); long y = int64.parse(form[string.format("questions[{0}].selectedanswer", i)]); if (x > 0 && y > 0) { selectedanswers.add(new selectedanswer() { questionid = x, answerid = y }); } }
c# asp.net-mvc model-view-controller radio-button formcollection
No comments:
Post a Comment