Remote ViewModel validation of nested objects not working

后端 未结 3 851
北恋
北恋 2020-12-31 13:02

I have a class user which looks like this:

public class User
{
    public int UserId { get; set; }

    [Required(ErrorMessage = \"A username is required.\")         


        
3条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 13:56

    Inheritance seems like a standard way of adding functionality in this case. How about having your RegistrationViewModel derive from the UserViewModel:

    public class RegistrationViewModel : UserViewModel
    {
        [DisplayName("Password confirmation")]
        [Required]
        [Compare("Password", ErrorMessage = "The password do not match")]
        public string PasswordConfirmation { get; set; }
    }
    

    and:

    public ActionResult UsernameExists(string Username)
    {
       ...
    }
    

提交回复
热议问题