In partial view I work with textboxes like this.
@model Dictionary<string, string>
@Html.TextBox("XYZ", @Model["XYZ"])
How can i generate radiobuttons, and get the desired value in the form collection as YES/NO True/False) ? Currently i am getting null for "ABC" if i select any value for the below.
<label>@Html.RadioButton("ABC", @Model["ABC"])Yes</label>
<label>@Html.RadioButton("ABC", @Model["ABC"])No</label>
Controller
public int Create(int Id, Dictionary<string, string> formValues)
{
//Something Something
}
Simply :
But you should always use strongly typed model as suggested by cacho.
This works for me.
In order to do this for multiple items do something like:
I wanted to share one way to do the radio button (and entire HTML form) without using the @Html.RadioButtonFor helper, although I think @Html.RadioButtonFor is probably the better and newer way (for one thing, it's strongly typed, so is closely linked to theModelProperty). Nevertheless, here's an old-fashioned, different way you can do it:
This code can go in a myView.cshtml file, and also uses classes to get the radio-button (checkbox) formatting.