@model MvcRequiredCheckbox.SampleViewModel
<title>ASP.NET MVC - Required Checkbox with Data Annotations</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
.field-validation-error {
<div class="col-md-6 col-md-offset-3">
<h1>ASP.NET MVC - Required Checkbox with Data Annotations</h1>
@using (Html.BeginForm())
@Html.CheckBoxFor(model => model.IsCurrent, new { @id = "IsCurrent"})
@Html.LabelFor(x => x.IsCurrent)
@Html.ValidationMessageFor(x => x.IsCurrent)
@Html.LabelFor(model => model.ToDate, new { @class = "control-label col-md-2" })
@Html.TextBoxFor(model => model.ToDate,new{@id="ToDate",@type="date"})
@Html.ValidationMessageFor(model => model.ToDate)
<button type="submit" class="btn btn-success submit">Submit</button>
<div class="credits text-center">
<a href="http://jasonwatmore.com/post/2013/10/16/ASPNET-MVC-Required-Checkbox-with-Data-Annotations.aspx">ASP.NET MVC - Required Checkbox with Data Annotations</a>
<a href="http://jasonwatmore.com">JasonWatmore.com</a>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/mvc/5.2.3/jquery.validate.unobtrusive.js"></script>
$('#IsCurrent').change(function(){
if ($('#IsCurrent').is(':checked') == true){
$('#ToDate').val('continuing').prop('disabled', true);
$('#ToDate').prop('disabled', false);
console.log('unchecked');