Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Html.RadioButtonFor with a boolean isn't writing Checked="Checked"
    primarykey
    data
    text
    <p>I am having an issue using the RadioButtonFor helper. When the value passed in is true, it isn't displaying a "check" in either radio button. When the value is false, it works just fine.</p> <p>I copied this code from the project I am working on and created a sample application and I was able to replicate the issue. If I hard coded the value to true or false it seems to work, but when I use the "!string.IsNullOrEmpty(allgroups)" it doesn't.</p> <p>From the View:</p> <pre><code>&lt;div&gt; @Html.RadioButtonFor(m =&gt; m.AllGroups, true) All Groups @Html.RadioButtonFor(m =&gt; m.AllGroups, false) Current Groups &lt;/div&gt; </code></pre> <p>From the ViewModel:</p> <pre><code> public bool AllGroups { get; set; } </code></pre> <p>From the Controller:</p> <pre><code>public ActionResult Index(string allgroups) { var model = new ProgramGroupIndexViewModel { AllGroups = !string.IsNullOrEmpty(allgroups) }; return View(model); } </code></pre> <p>From view source in IE:</p> <pre><code>&lt;div&gt; &lt;input id="AllGroups" name="AllGroups" type="radio" value="True" /&gt; All Groups &lt;input id="AllGroups" name="AllGroups" type="radio" value="False" /&gt; Current Groups &lt;/div&gt; </code></pre> <p>From view source when value of AllGroups is false (note it works):</p> <pre><code>&lt;div&gt; &lt;input id="AllGroups" name="AllGroups" type="radio" value="True" /&gt; All Groups &lt;input checked="checked" id="AllGroups" name="AllGroups" type="radio" value="False" /&gt; Current Groups &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload