0

I have a database generated model with an int property (not list or anything fancy). Trying to map this property to 2 checkboxes that represent "contact method".

  1. text, 2. email, or both, and read this as a single number in the DB column 1, 2 or 3 for both.

Tried setting the values in regular html inputs and using @html.checkboxfor(x => x.boolproperty), what I can't figure out is how to get a value from both checkboxes.

Tober
  • 11
  • 2

1 Answers1

1

x is your viewmodel and boolproperty is a field of the viewmodel. If you do the same as you do right now for the second checkbox aswel (so create a second field in the viewmodel for that) and then check in the controller:

int number = 0;
if (boolproperty && !boolproperty2)
{
 number = 1;
}
else if (!boolproperty && boolproperty2)
{
 number = 2;
}
else if (boolproperty && boolproperty2)
{
 number = 3;
}
Svenmarim
  • 3,633
  • 5
  • 24
  • 56