ページに fromDate と ToDate の 2 つの日付フィールドがあります。ToDate は FromDate より大きくなければなりません。クライアント側で検証する必要があります。クリッド側の検証に Foolprof を使用しています
参照を追加
using Foolproof;
スクリプトが追加されました
<script src="~/Scripts/mvcfoolproof.unobtrusive.min.js"></script> <script src="~/Scripts/MvcFoolproofJQueryValidation.min.js"></script> <script src="~/Scripts/MvcFoolproofValidation.min.js"></script>
私のモデルには以下のコードが含まれています
[Required(ErrorMessage = "The start date is required")] public DateTime StartDate { get; set; } [Required(ErrorMessage = "The end date is required")] [GreaterThan("StartDate")] public DateTime EndDate { get; set; }
そしてコントローラーでデフォルトの足場を使用して行われます。
私の.cshtmlには、以下の日付のコードが含まれています
<div class="form-group">
@Html.LabelFor(model => model.StartDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.StartDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.StartDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EndDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EndDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EndDate, "", new { @class = "text-danger" })
</div>
</div>
現在、私の検証はクライアント側では機能していませんが、送信ボタンをクリックするとサーバー側で機能しています。
私にいくつかのガイダンスを提供してください..
ありがとうございました。