即使没有错误,警报框仍显示

时间:2019-06-27 22:24:01

标签: razor model-view-controller input alert show-hide

我有这个登录页面,我需要在其中验证用户名/密码,我使用警报警报错误类来显示来自数据注释的错误消息。但是错误框保持可见。 这是我在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>

0 个答案:

没有答案