if I have this html checkbox list code, how in mvc in my post action method how can I get the Id of that checkboxlist? because whith string[] dias i get just the values by example(“lunes” “martes” … etc)
(usgin this example for make my checkboxlist => example)
[HttpPost]
public ActionResult Editar(cliente cliente, string[] dias)
{
}
html
<input id="1" type="checkbox" value="Lunes" name="dias">
Lunes
<input id="2" type="checkbox" value="Martes" name="dias">
Martes
<input id="3" type="checkbox" value="Miercoles" name="dias">
Miercoles
<input id="4" type="checkbox" value="Jueves" name="dias">
Jueves
<input id="5" type="checkbox" value="Viernes" name="dias">
Viernes
<input id="6" type="checkbox" value="Sabado" name="dias" checked="checked">
Sabado
<input id="" type="checkbox" value="Domingo" name="dias">
Domingo
You can’t get the
id. Theidattribute is never sent to the server when you submit an form. That’s how HTML works. Only thevalueis sent. But checkboxes are a little different because only thevalueattribute of the checked checkboxes is sent to the server.So, simply use the
valueattribute for that purpose:Now in your
string[] diasparameter you will get a list of the selected ids. Then if you need to get the corresponding names go ahead and query your data store where they reside given this id.