jQuery规则删除验证

时间:2016-04-01 17:48:32

标签: jquery

我目前有一个asp.net Mvc5应用程序,它有许多字段(一周中的几天)作为时间跨度。这样,用户就可以记录他们在案件上花费的时间。从阅读Range and DisplayFormat Attributes on TimeSpan我发现我需要包含以下内容

<script>
$(document).ready(function () {
    $("#ScheduleTime").rules('remove', 'range');
});

这很好,适用于我的第一个领域。我更改了代码以包含我的所有字段。

<script>
$(document).ready(function () {
    $("#Monday, #Tuesday, #Wednesday, #Thursday, #Friday, #Saturday, #Sunday").rules('remove', 'range');
});

我当前的观点是通过剃刀语法

完成的
   <div class="form-group">
        @Html.LabelFor(model => model.Monday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Monday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Monday, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.Tuesday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Tuesday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Tuesday, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.Wednesday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Wednesday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Wednesday, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.Thursday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Thursday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Thursday, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.Friday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Friday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Friday, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.Saturday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Saturday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Saturday, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.Sunday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Sunday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Sunday, "", new { @class = "text-danger" })
        </div>
    </div>

然而,这不起作用。我该如何解决这个问题?

非常感谢

1 个答案:

答案 0 :(得分:0)

我通过为每一天创建新规则来解决这个问题。不确定这是否是正确的方法,但它解决了我的问题

JobDataMap