私はカスタム日付のバリデーションを持っており、 thisのリンクで説明した通りです。以下は私の機種コードです:MVCビューのValidationMessageが表示されない
以下[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}",ApplyFormatInEditMode=true)]
[DisplayName("Sch.Start Date:")]
[DataType(DataType.Date)]
[ValidProjectDate(ErrorMessage="Project Start Date cannot be greater than Project End Date.")]
public DateTime? ProjectScheduleStartDate { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
[DisplayName("Sch.End Date:")]
[DataType(DataType.Date)]
[ValidProjectDate(ErrorMessage = "Project End Date cannot be less than or Equal to Current Date.")]
public DateTime? ProjectScheduleEndDate { get; set; }
` は、ビューの私のコードです:以下
<div class="form-group">
@Html.LabelFor(model => model.ProjectScheduleStartDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProjectScheduleStartDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProjectScheduleStartDate, "*", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ProjectScheduleEndDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProjectScheduleEndDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProjectScheduleEndDate, "*", new { @class = "text-danger" })
</div>
</div>
<hr/>
@Html.ValidationSummary(true, "Please correct below errors", new { @class = "text-danger" })
コントローラの私のコードです。でも
if (ModelState.IsValid)
{
ProjectManager pm = new ProjectManager();
pm.AddProjects(prj);
ViewBag.Result = "Record Inserted Successfully.";
ModelState.Clear();
}
else
{
ModelState.AddModelError(string.Empty, "An Error has happened");
}
return View("AddNewProject");
私は検証メッセージを表示しようとしましたがモデルクラスで述べたように、私は検証メッセージの代わりに星の画像しか得ていません。ただし、検証サマリで指定されたエラーメッセージが表示されています。しかし、モデルクラスにメッセージを表示したい。どんな手掛かり?