Use a radio button or a single checkbox.
I'm not a fan of reinventing the wheel or making code more complex than necessary but here you go.
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div>
@Html.Label("Did You Meet/Speak to Staff", htmlAttributes: new { @class = "control-label col-md-5" })
<div class="col-md-7">
<input type="checkbox" id="SpeakStuffYes" name="SpeakStuff" value="true" class="speak-stuff-checkbox" @(Model.SpeakStuff ? "checked" : "") />
Yes
<input type="checkbox" id="SpeakStuffNo" name="SpeakStuff" value="false" class="speak-stuff-checkbox" @(!Model.SpeakStuff ? "checked" : "") />
No
</div>
</div>
@section scripts
{
<script>
$('.speak-stuff-checkbox').on('change', function () {
var id = $(this).attr('id');
var isChecked = $(this).prop('checked');
if (id == 'SpeakStuffYes') {
$('#SpeakStuffNo').prop('checked', !isChecked);
}
else {
$('#SpeakStuffYes').prop('checked', !isChecked);
}
});
</script>
}
namespace MvcDemo2.Controllers
{
public class CheckboxController : Controller
{
// GET: Checkbox
public ActionResult Index()
{
ResignationRequester model = new ResignationRequester() { SpeakStuff = false };
return View(model);
}
}
public class ResignationRequester
{
public bool SpeakStuff { get; set; }
}
}