首页 新闻 赞助 找找看

请教一个mvc CompareAttribute的问题

0
悬赏园豆:5 [已解决问题] 解决于 2014-10-15 16:57
public class RegisterViewModel
    {
        public Account Account { get; set; }

        [Display(Name = "ConfirmPassword", ResourceType = typeof(Resource))]
        [Required(ErrorMessageResourceName = "RequiredErrorMessage", ErrorMessageResourceType = typeof(Resource))]
        [DataType(DataType.Password)]
        [Compare("Password")]
        public string ConfirmPassword { get; set; }
    }

出错!
请教一下,[Compare("Password")]怎样才能获取到Password,它在Account类里面!

时光刺客的主页 时光刺客 | 初学一级 | 园豆:60
提问于:2014-10-15 16:39
< >
分享
最佳答案
1

[Compare("Account.Password")]

收获园豆:5
Launcher | 高人七级 |园豆:45045 | 2014-10-15 16:47

你确定你有测试过?怎么不行的

时光刺客 | 园豆:60 (初学一级) | 2014-10-15 16:50

@时光刺客: 没有,我猜测的,WPF 中绑定支持此路由方式,所以我认为 MVC 中也可以借鉴此做法,估计后续版本的 MVC 会支持此语法。

 

所以你需要修改你的 ViewModel,如下:

public class RegisterViewModel

{

   public string Password {get{return Account.Password;} set {Account.Password = value;}}

}

Launcher | 园豆:45045 (高人七级) | 2014-10-15 16:53

@Launcher: 嗯!好的!谢谢指教!

时光刺客 | 园豆:60 (初学一级) | 2014-10-15 16:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册