asp.net core mvc tag helper for bootstrap toggle

Solution 1:

Okay so after hours of messing around trying different things and scouring the Internet I finally figured it out. I have edited the code above to the working version.

Basically you need to do two things:

  1. output an attribute "value" set to "true" so when the checkbox is checked (toggle set to "Yes") the value returned is "true" instead of "on", which is the default for checkboxes.
  2. Check the model property and add an attribute for "checked" if it is true.

I have highlighted both in the original post with comments.

I hope this helps someone else out there as I wasted a lot of time figuring this out. Toggles look WAY better than checkboxes in modern web apps so it was well worth the effort IMHO.