Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class UserModel
- {
- [Key]
- [Required]
- [StringLength(20, MinimumLength = 4)]
- public string Username { get; set; }
- [Required]
- [EmailAddress]
- [DataType(DataType.EmailAddress)]
- public string Email { get; set; }
- [Required]
- [DataType(DataType.Password)]
- [StringLength(20, MinimumLength = 4)]
- public string Password { get; set; }
- public bool IsValid { get; set; }
- }
- public class UserViewModel {
- [Required]
- [StringLength(20, MinimumLength = 4)]
- public string Username { get; set; }
- [Required]
- [EmailAddress]
- [DataType(DataType.EmailAddress)]
- public string Email { get; set; }
- [Required]
- [DataType(DataType.Password)]
- [StringLength(20, MinimumLength = 4)]
- public string Password { get; set; }
- }
- public ActionResult Post([FromBody] UserViewModel viewModel) {
- if(ModelState.IsValid) {
- //create new model
- var model = new UserModel {
- Username = viewModel.Username,
- Email = viewModel.Email,
- Password = viewModel.Password
- };
- //or model retrieved from data storage
- //...some other code...
- model.IsValid = true; //only the server can modify this value
- //...
- }
- //...
- }
Add Comment
Please, Sign In to add comment