Flags when sent to the server are a little strange. If checked, the browser will send name=value , as in
<input type="checkbox" name="name" value="value" />
But if the flag is not , the server does not send anything.
<input type="checkbox" name="Check1" id="Checks1" value="Hello" checked="checked"/> <input type="checkbox" name="Check1" id="Checks1" value="Hello1" /> <input type="checkbox" name="Check1" id="Checks1" value="Hello2" />
The result is Check1 = Hello
What does this mean if all of your flags are connected, naming them the same way will fill the same attribute of your ActionMethod. If this attribute is an enumeration, it will contain only those that have been marked.
If you have this in your opinion:
<input type="checkbox" name="MyValues" value="1" checked="checked"/> <input type="checkbox" name="MyValues" value="2" /> <input type="checkbox" name="MyValues" value="3" />
and this is like the action method of your controller:
public ActionMethod MyAction(IEumerable<int> myValues)
The myValues variable will look like this:
myValues[0] == 1
It should also be noted that if you use the helper extension Html :
@Html.CheckBoxFor(m => m.MyValue)
Where MyValue is a bool , the extension will create a checkbox input tag, as well as a hidden input tag with the same name, which means that the value will always be passed to the controller method.
Hope this helps.