2016-04-01 140 views
0

我目前有一个asp.net Mvc5应用程序,它具有许多字段(星期几)作为时间跨度。这样用户就可以记录他们花在案件上的时间。从阅读Range and DisplayFormat Attributes on TimeSpan我发现我需要包括以下jQuery规则删除验证

<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> 

做然而,这不工作的最新观点。我如何解决这个问题?

非常感谢

+0

什么是'.rules()'jQuery插件?它支持选择多个元素吗? – epascarello

+0

显示DOM请(标记示例) – thinice

+0

这是jquery'rules()'插件http://jqueryvalidation.org/rules/ – markabarmi

回答

0

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

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