I viewed some topics here but I still have a problem with getting values from checkboxes.
Part of Model :
public Dictionary TargetL
Create all the checkboxes with the same name. In this sample I'm using 'SelectedTargetLanguages'.
@using (Html.BeginForm())
{
foreach (var item in Model.TargetLanguages)
{
<label>
@Html.CheckBoxFor(m => m.SelectedTargetLanguages, item.value)
@item.KeyName
</label>
}
<br/>
@Html.SubmitButton("Actualizar listado")
}
Then, in your action the parameter must be an array of strings like this:
public ActionResult AddDictionary(string[] selectedTargetLanguages)
Note that the name of the argument is the same name of the checkboxes. (It works even with the different casing).
You should use explicit arguments like this, rather than the generic FormCollection
. Anyway, if you use FormCollection, you shpuld also receive the array.
I have asked same type of question previously. Please check the following links
MVC3 @Html.RadioButtonfor Pass data from view to controller
MVC3 @html.radiobuttonfor
I think this might helps you.