c# - FormCollection not getting correct value for Radio Button -


when post formcollection , try value of radio button, takes value of last radio button (no matter 1 checked). why doing this? temporary workaround create hidden value , add onclick js method. i've tried using pure html code same result.

code view

@html.radiobutton("radio", "no", true, new { id = "radio0"}) + " no"); @html.radiobutton("radio", "yes", false, new { id = "radio1"}) + " yes"); 

resulting html

<input checked="checked" id="radio0" name="radio" type="radio" value="no"> no <input id="radio1" name="radio" type="radio" value="yes"> yes 

controller code

[httppost, validateinput(false)] public actionresult mypostback(formcollection form) {     string radio = form["radio"]; //************** "yes"     return view("myview"); } 

actually not replicate issue. correctly identifies selected radio button on postback @ controller.

you may want check code view (with given syntax view, shouldn't render page in first place & should throwing compilation error)

this view testing against

@{     viewbag.title = "myview"; }  <h2>mypostback</h2> @using (html.beginform()) {     @html.radiobutton("radio", "no", true, new { id = "radio0"}) @:no     @html.radiobutton("radio", "yes", false, new { id = "radio1"}) @:yes     <input type ="submit" runat="server" id="btnsubmit" /> } 

edit

based on comments, since using devexpress, first go through provided documentation. should point in right direction. doing google search,found out in addition radiobutton extension there radiobuttonlist extension. here few links you.

devexpress documentation (radibuttonlist)

a working example on using radiobuttonlist

a discussion thread on radiobutton (though couldn't find example on how use radiobutton; according thread can use radiobutton, if has option choose between 2 choices; else need opt radiobuttonlist)

also mentioned bettor pass model/viewmodel rather sending on formcollection


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -