jquery - ASP.NET MVC RadioButtonFor Not Selected On Load -


there many other questions here on stack overflow , elsewhere, have spent far time sifting through them answers not ask 1 myself. have tried many of solutions found here , none of them work.

my problem stated in title; radio buttons not being set on page load , can't figure out why.

in code below model has boolean value cansubmit, cansubmityes , cansubmitno id's generated id's using

viewcontext.viewdata.templateinfo.getfullhtmlfieldid("cansubmityes") 

and

viewcontext.viewdata.templateinfo.getfullhtmlfieldid("cansubmitno") 

my radio buttons , corresponding labels set following:

@html.labelfor(function(m) m.cansubmit, "yes", new {.for = cansubmityes}) @html.radiobuttonfor(function(m) m.cansubmit, true, new {.id = cansubmityes, .class = "submit-toggle-yes"})  @html.labelfor(function(m) m.cansubmit, "no", new {.for = cansubmitno}) @html.radiobuttonfor(function(m) m.cansubmit, false, new {.id = cansubmitno, .class = "submit-toggle-no"}) 

what have tried:

  • setting checked="checked" properties in the helpers htmlattributes collection
  • strip out of htmlhelper code stuff , use basic <input type="radio" /> controls , reason it's still not being checked on load.
  • tried using jquery event set 'checked' property of them on load of document, too, did not work. (via .prop("checked", true))
  • changed format of html helper "false" false try force understand property boolean , not string

there no other javascript events setting values these controls. when observe me clicking buttons there no html values changed on objects - leads me think 'clicked'/'checked' property pseudo property or state browser holds.

have missed critical or way off base here?

thanks in advance!

update

i have determined has local variables i'm using. have them in basic <input>'s again , if don't connect them work expected. when try pair them common name (the way tie them together) don't work.

<input name="radio@(model.id)" id="@cansubmityes" type="radio" class="submit-toggle-yes" @(if(submitterpermission.isselected, "checked='checked'", "")) /> <label for="@cansubmityes">yes</label>  <input name="radio@(model.id)" id="@cansubmitno" type="radio" class="submit-toggle-no" @(if(submitterpermission.isselected, "", "checked='checked'")) /> <label for="@cansubmitno">no</label> 

if remove name='' attribute correctly checks proper element on load. need these items unique there potentially 50+ of such parings on page.

i found had left question unanswered.

we did not find problem, ended following different approach. furthermore no longer work on project cannot adequately update question.


Comments