dimanche 5 mars 2017

Check if checkbox is checked MVC controller

On my MVC View I have a few checkboxes:

<form method="POST" id="formRegistration" action="Registration/SubmitRegistration" > 
//Other code...
    <input name="test1" type="checkbox" value="false" />
    <input name="test2" type="checkbox"  />
</form>

On the controller I get- using a POST request- the data and I insert it to the DataBase:

public void AddRegistered(Registration r)
{
//Other code...
     dParameters.Add("test1", r.test1.ToString());
     dParameters.Add("test2", r.test2.ToString());
//Other code...
}

The problem is that I keep getting a false value even if the checkbox is checked.

Wham am I missing?

Aucun commentaire:

Enregistrer un commentaire