我的視圖有一個文本框(電子郵件)和一個提交按鈕。如何根據MVC5顯示多條驗證消息
@using (Html.BeginForm("FindMyDetail", "ResetPassword", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Enter your email.</h4>
@Html.ValidationSummary(false, "", new { @class = "alert alert-danger" })
@Html.ValidationMessageFor(m=>m.Email)
<div class="form-group">
@Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@*@Html.TextBoxFor(m => m.Email, new { @class = "form-control", @value = @Html.DisplayFor(m => m.Email) })*@
@Html.TextBoxFor(m => m.Email, true, htmlAttributes: new { @class = "form-control", placeholder = "Enter Email Id you used to register" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Email Link" />
</div>
</div>
}
我在MVC的Web應用程序的視圖顯示多個驗證消息。
案例1:顯示驗證消息,當文本框留空時輸入電子郵件ID。
案例2:如果電子郵件存在,提交按鈕會觸發郵件。如果郵件失敗(false),則應該發送電子郵件不存在的驗證消息。 點擊提交按鈕會觸發一個控制器,該控制器會觸發給定的電子郵件。如果succesfull我將返回成功信息有不同的看法一樣,我將返回相同的視圖(EmailLink視圖)
在asp.net web表單執行,這似乎很容易,但看起來很不同,很不解,因爲上午如何在MVC實現這個新的。
編輯:我需要它使用自定義驗證實現。不使用數據交替。
這聽起來很基本的,所有應隨Visual Studio – JamieD77
的MVC項目模板覆蓋我需要一個模型的自定義驗證消息。 –
ModelState.AddModelError? –