2012-04-15 9 views
1

次のモデルを使用してユーザーの入力を制御し、ユーザーを登録します。 しかし、同じパスワードを入力してボタンを押すと、という確認パスワードが間違っているというメッセージが表示されます。MVC3での確認パスワードの問題

他のページでも動作しているのでモデルは正しいと思います。 この場合RegisterModelSecondは、EventFrontEndViewModelのメンバーです。

だから、私が[Compare("RegisterModel.Password", ErrorMessage = "The password and confirmation password do not match.")]とコメントしても動作するが確認は必要ない!

どのように手掛かりを修正するには?

public class EventFrontEndViewModel 
    { 
     public Page CurrentPage { set; get; } 

     public List<Event> Events { set; get; } 

     public List<Event> SubscribedEvents { set; get; } 

     public RegisterModelSecond RegisterModel { set; get; } 

     public EventFrontEndViewModel() 
     { 
      CurrentPage = new Page(); 
      Events = new List<Event>(); 
      RegisterModel = new RegisterModelSecond(); 
      SubscribedEvents = new List<Event>(); 
     } 
    } 

登録モデル

public class RegisterModelSecond 
    { 
     [Required] 
     [Display(Name = "User name")] 
     public string UserName { get; set; } 

     [Required] 
     [DataType(DataType.EmailAddress)] 
     [Display(Name = "Email address")] 
     public string Email { get; set; } 

     [Required] 
     [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] 
     [DataType(DataType.Password)] 
     [Display(Name = "Password")] 
     public string Password { get; set; } 

     [Required] 
     [DataType(DataType.Password)] 
     [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] 
     [Display(Name = "Confirm password")] 
     [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] 
     public string ConfirmPassword { get; set; } 
    } 

とHTML

<div class="editor-label"> 
             @Html.LabelFor(m => m.RegisterModel.Password) 
            </div> 
            <div class="editor-field"> 
             @Html.PasswordFor(m => m.RegisterModel.Password) 
             @Html.ValidationMessageFor(m => m.RegisterModel.Password) 
            </div> 
            <div class="clear"> 
            </div> 
            <div class="editor-label"> 
             @Html.LabelFor(m => m.RegisterModel.ConfirmPassword) 
            </div> 
            <div class="editor-field"> 
             @Html.PasswordFor(m => m.RegisterModel.ConfirmPassword) 
             @Html.ValidationMessageFor(m => m.RegisterModel.ConfirmPassword) 
            </div> 
            <div class="clear"> 
            </div> 

答えて

2

私は、正しい答えがここにMVC 3 Client-Side Compare Validation

これは、クライアント側の検証スクリプトのバグであるが見つかりました:jquery.validate。邪魔にならない.js

ライン〜284で

あなたはこれを見つけることができます。これに

element = $(options.form).find(":input[name=" + fullOtherName + "]")[0]; 

変更を:

element = $(options.form).find(":input[name='" + fullOtherName + "']")[0]; 

name属性は、単一引用符を必要とします。


MINバージョンを使用する場合は、追加する必要があります。そこにも変更する必要があります。

+1

ありがとうございました...完全にクレイジーなバグ... – kape123

+1

うわー..あなたは私の日を守る..ありがとう –

関連する問題