Using Html.RadioButtonFor with a boolean isn't writing Checked="Checked"

asp.net-mvc-3

Solution

The model binding is getting confused because you named your action parameter the same as your model property. Change the name of your `Index` action parameter, and it should work.

public ActionResult Index(string showAllGroups)
{
    var model = new ProgramGroup
                    {
                        AllGroups = !string.IsNullOrEmpty(showAllGroups);
                    };
    return View(model);
}

Problem

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. 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. From the View: ``` <div> @Html.RadioButtonFor(m => m.AllGroups, true) All Groups @Html.RadioButtonFor(m => m.AllGroups, false) Current Groups </div> ``` From the ViewModel: ``` public bool AllGroups { get; set; } ``` From the Controller: ``` public ActionResult Index(string allgroups) { var model = new ProgramGroupIndexViewModel { AllGroups = !string.IsNullOrEmpty(allgroups) }; return View(model); } ``` From view source in IE: ``` <div> <input id="AllGroups" name="AllGroups" type="radio" value="True" /> All Groups <input id="AllGroups" name="AllGroups" type="radio" value="False" /> Current Groups </div> ``` From view source when value of AllGroups is false (note it works): ``` <div> <input id="AllGroups" name="AllGroups" type="radio" value="True" /> All Groups <input checked="checked" id="AllGroups" name="AllGroups" type="radio" value="False" /> Current Groups </div> ```

Original source