How to map a checkbox as bool (bit in SQL server)?

0

I know they always ask for code, but my question is basic. I also know that you can qualify it as "general knowledge" or "subjective response", but although it seems incredible, there are not many topics in Spanish that speak of the subject.

Basically I have an HTML Helper Checkbox and I want to capture its value with AJAX / JSON and send it to my controller so I can save it in the model.

Now the problem is that I do not know how to treat the checkbox because its value can be "on" or Nothing, when I want to capture that to take it to the BD the model requires me to make it "true" or "false" , so I do the conversion in the controller. Now the interesting thing is that when I see the BD I find that the possible values (bit) can be 0 or 1 and when I do the mapping instead of saving 1 (true) it saves me 0. Someone knows how to "convert" the data so that consider it as 1 or 0 in the BD? thanks !!

    
asked by seojedaperez 26.05.2017 в 08:34
source

1 answer

0

You could add these input to control the value that arrives when it is selected or not:

<form>
  <input type='hidden' value='0' name='selfdestruct'>
  <input type='checkbox' value='1' name='selfdestruct'>
</form>

If it is 1, you convert it to true in the model and if it is zero to false.

Then again to 1 and 0 in the sql.

This solution is not optimal but it answers your question, regards

    
answered by 26.05.2017 / 09:06
source