所以,我試圖使用自定義驗證的用戶名和電子郵件,但它的工作,但只有一個紅色框。它實際上沒有顯示。這是我的代碼遠程驗證顯示紅色框但沒有錯誤信息? ASP - MVC 5
[Required]
[Display(Name = "User name")]
[System.Web.Mvc.Remote("UserExists", "Account", ErrorMessage = "UserName already exists, please pick another one.")]
[Editable(true)]
控制器... 公共JsonResult UserExists(用戶名字符串) {
var user = UserManager.FindByName(UserName);
return Json(!db.AspNetUsers.Any(x => x.UserName == UserName),
JsonRequestBehavior.AllowGet);
}
所以,是的,它顯示的紅色方塊被證明該用戶名存在,但它實際上並沒有顯示錯誤信息。如果我要提交它會顯示錯誤消息,但否則不會。 這是模型..
<script src="~/Scripts/jquery-2.0.3.js"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<fieldset>
@Html.AntiForgeryToken()
<h4>Create a new account.</h4>
<hr />
@Html.ValidationSummary()
<div class="form-group">
@Html.LabelFor(m => m.UserName, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.UserName, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.UserName)
</div>
是什麼的觀點是什麼樣子?您是否真的輸出錯誤消息'@ Html.ValidationMessageFor(model => model.UserName)' – DGibbs
嘿,我已經更新了它.. –