Can't get RequiredIfTrue working for MVC 5

Apr 27, 2015 at 12:49 PM
Model
 public class WorkPattern
    {
        public int ID { get; set; }
        public bool MondayTrue { get; set; }
        [DataType(DataType.Time, ErrorMessage = "Incorrect time")]             
        [RequiredIfTrue("MondayTrue", ErrorMessage="Day has been marked as working")]
        public DateTime? MondayStart { get; set; }
        [DataType(DataType.Time, ErrorMessage = "Incorrect time")]   
@model OrwellFrontEnd.NewEmp.WorkPattern

@{
    ViewBag.Title = "ViewEmpDetails";
    Layout = null;
}

@using (Html.BeginForm(null, null, FormMethod.Post, new { name = "myForm", id = "myForm" }))
{

    @Html.AntiForgeryToken()

    <div class="form-group">
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

        <div style="padding-left: 5px"><h1>Employee work pattern</h1></div>

        <div style="display: table;">

            <div style="display: table-row;">
                <div class="div-empty-cell" , style="display: table-cell"> &nbsp; </div>
            </div>

            <div style="display: table-row;">
                <div class="div-label-checkbox" , style="display: table-cell">@Html.CheckBoxFor(model => model.MondayTrue, new { id = "txtMondayTrue" } )</div>
                <div class="div-label-text" , style="display: table-cell"> @Html.LabelFor(model => model.MondayStart) </div>
                <div class="div-EditorFor" , style="display: table-cell"> @Html.EditorFor(model => model.MondayStart, new { htmlAttributes = new { id = "txtMondayStart", disabled = "disabled" } }) </div>
                <div class="div-val-checkbox" , style="display: table-cell"> @Html.ValidationMessageFor(model => model.MondayStart, "", new { @class = "text-danger" }) </div>
                <div class="div-label-text" , style="display: table-cell"> @Html.LabelFor(model => model.MondayEnd) </div>
                <div class="div-EditorFor" , style="display: table-cell"> @Html.EditorFor(model => model.MondayEnd, new { htmlAttributes = new { id = "txtMondayEnd", disabled = "disabled" } }) </div>
                <div class="div-val-checkbox" , style="display: table-cell"> @Html.ValidationMessageFor(model => model.MondayEnd, "") </div>
            </div>
           


        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="button" value="Back" class="btn btn-default" onclick="AjaxBack('@Url.Content("~/TreeView/_NewEmpSecond")');" />
                <input type="button" value="Next" class="btn btn-default" onclick="AjaxGoodRedirect('@Url.Content("~/TreeView/_NewEmpThird")');" />
            </div>
        </div>
    </div>
}


<script>
    $("#txtMondayTrue").click(function (event) {
        if ($(this).is(":checked")) {
            $('#txtMondayStart').prop("disabled", false).val("");
            $('#txtMondayEnd').prop("disabled", false).val("");
        }
        else {
            $('#txtMondayStart').prop("disabled", true).val("");
            $('#txtMondayEnd').prop("disabled", true).val("");
        }
    });
</script>

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="~/Scripts/MvcFoolproofJQueryValidation.min.js" type="text/javascript"></script>
<script>
    var urlAction = "@Url.Content("~/Treeview/_NewEmpThird")";
    function AjaxGoodRedirect(urlAction) {
        console.log(urlAction);
        var form = $("#myForm");
        form.validate();
        if (form.valid()) {
            $.ajax({
                type: "POST",
                url: urlAction,
                data: JSON.stringify({
                    MondayStart: $("#txtMondayStart").val()
                    , MondayEnd: $("#txtMondayEnd").val()
                    , TuesdayStart: $("#txtTuesdayStart").val()
                    , TuesdayEnd: $("#txtTuesdayEnd").val()
                    , WednesdayStart: $("#txtWednesdayStart").val()
                    , WednesdayEnd: $("#textWednesdayEnd").val()
                    , ThursdayStart: $("#txtThursdayStart").val()
                    , ThursdayEnd: $("#txtThursdayEnd").val()
                    , FridayStart: $("#txtFridayStart").val()
                    , FridayEnd: $("#txtFridayEnd").val()
                }),
                datatype: "JSON",
                contentType: "application/json; charset=utf-8",
                success: function (returndata) {
                    if (returndata.ok)
                        $("#detailView").load(returndata.newurl);
                }
            }
            );
        }
    }
</script>
<script>
    function AjaxBack() {
        $("#detailView").load("/TreeView/_NewEmpSecond");
    }
</script>
When I tick the box and press submit it moves to the next page. Have I set this up wrong?
Apr 27, 2015 at 12:58 PM
nevermind, foxed now was missing some js files

<script src="~/Scripts/mvcfoolproof.unobtrusive.min.js"></script>
<script src="~/Scripts/MvcFoolproofJQueryValidation.min.js"></script>
<script src="~/Scripts/MvcFoolproofValidation.min.js"></script>