Modeling and validating a form with multiple submit

后端 未结 1 1682
傲寒
傲寒 2021-01-22 23:27

I am trying to figure out the proper way to model and validate a form with multiple form tags and multiple submit buttons using ASP.Net Core 2. What I have is a form where a use

1条回答
  •  走了就别回头了
    2021-01-22 23:55

    I would break my models into two class and then use a ViewModel instead:

    public class SignIn
    {
        [Required]
        public string Username { get; set; }
        [Required]
        public string Password { get; set; }
    }
    
    public class SignUp
    {
        [Required]
        public string FirstName { get; set; }
        [Required]
        public string LastName { get; set; }
        [Required]
        public string CellNumber { get; set; }
    }
    
    public class LandingViewModel
    {
        public SignIn SignIn { get; set; }
        public SignUp SignUp { get; set; }
    }
    

    Then:

    @model MyApp.ViewModels.LandingViewModel
    SignIn.Username, SignIn.Password, SignUp.FirstName,...
    

    0 讨论(0)
提交回复
热议问题