我有这个登录页面,我需要在其中验证用户名/密码,我使用警报警报错误类来显示来自数据注释的错误消息。但是错误框保持可见。 这是我在MVC的第一个项目,不确定我在做什么。 代码如下:
[DataType(DataType.Text)]
[Required(ErrorMessage = "message")]
public string password { get; set; }
[MaxLength(24), MinLength(5)]
[Required(ErrorMessage = "message")]
public string CVR { get; set; }
CSHTML代码如下所示:-
<div class="portal-info">
<p class="user">
<label class="form-label" for="contactPhone">
name
</label>
@Html.EditorFor(model => model.CPR, new {
htmlAttributes = new { @class = "form-input", PlaceHolder = "name",
maxlength = "10", Type="HtmlInputFile", id=name , value=""} })
<br>
@Html.ValidationMessageFor(model => model.CVR, "",
new { @class = "alert alert-error" })
</p>
<p class="user">
<label class="form-label" for="contactPhone">
password
</label>
@Html.EditorFor(model => model.password, "Password",
new { htmlAttributes = new { @class = "form-input", PlaceHolder =
"required password" } })
<br>
@Html.ValidationMessageFor(model => model.password,
"", new { @class = "alert alert-error" })
</p>
</div>