2016-04-01 15 views
0

私は現在、timespansとしていくつかのフィールド(曜日)を持つ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'); 
    }); 
関連する問題