2017-03-28 3 views
0

MVC 5에 익숙하지 않으며 암호 확인 필드에 동일한 암호를 입력하려고 할 때마다 항상 유효성 검사 메시지 [Compare]이 발생합니다. 이것은 일반적인 문제입니까? 내 코드는보기MVC 5 암호 비교 항상 유효성 확인

<div class="form-group"> 
    @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> 
     @Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control" } }) 
     @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" }) 
    </div> 
</div> 
<div class="form-group"> 
    @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> 
     @Html.PasswordFor(m => m.Password, new { @class = "form-control required" }) 
     @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" }) 
    </div> 
</div> 
<div class="form-group"> 
    @Html.LabelFor(model => model.ConfirmPassword, htmlAttributes: new { @class = "control-label col-md-2" }) 
    <div class="col-md-10"> 
     @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control required" }) 
     @Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" }) 
    </div> 
</div> 
+0

양식을 제출할 작업을 표시 할 수도 있습니까? – Usman

+0

두 개의 CompareAttribute 클래스가 있습니다 - 어떤 클래스를 사용하고 있는지 알고 계십니까? –

+0

@TiesonT. 그들은 둘 다 똑같이 일하지 않습니까? – Usman

답변

0
@model FailTracker.Models.LoginUser //your model 

@{ 
ViewBag.Title = "Test"; 
} 

@using (Html.BeginForm()) {

// your view code goes here 

<div class="form-group"> 
<button type="submit" class="btn btn-success">Submit</button> 
</div> 

} 
에 여기

[Required] 
[StringLength(MaxUserNameLength)] 
[Display(Name = "Username")] 
public virtual string UserName { get; set; } 

[Required] 
[DataType(DataType.Password)] 
[StringLength(MaxPasswordLength)] 
public virtual string Password { get; set; } 

[Required] 
[DataType(DataType.Password)] 
[Display(Name = "Confirm Password")] 
[Compare("Password", ErrorMessage = "Doesn't Match")] 
public string ConfirmPassword { get; set; } 

과 :

여기 모델에서 내 코드입니다

정상적으로 작동합니다. 나는 코드에 어떤 문제도 보지 못했다.