From 82fd44ba0f6de5c15cf0c332f6f8c276f940b085 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 14 Jul 2021 21:31:29 +1000 Subject: [PATCH] e.g. 3.13 Applying Validation to the GuestResponse Model Class --- .../PartyInvites/Models/GuestResponse.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/chap3_your_first_mvc_app/PartyInvites/Models/GuestResponse.cs b/chap3_your_first_mvc_app/PartyInvites/Models/GuestResponse.cs index c91944f..bb7423c 100644 --- a/chap3_your_first_mvc_app/PartyInvites/Models/GuestResponse.cs +++ b/chap3_your_first_mvc_app/PartyInvites/Models/GuestResponse.cs @@ -1,10 +1,22 @@ -namespace PartyInvites.Models +using System.ComponentModel.DataAnnotations; + +namespace PartyInvites.Models { public class GuestResponse { + [Required(ErrorMessage = "Please enter your name")] public string Name { get; set; } + + [Required(ErrorMessage = "Please enter your email address")] + [RegularExpression(".+\\@.+\\..+", + ErrorMessage = "Please enter a valid email address")] public string Email { get; set; } + + [Required(ErrorMessage = "Please enter your name")] public string Phone { get; set; } + + [Required(ErrorMessage = "Please specify whether you'll attend")] public bool? WillAttend { get; set; } + } } \ No newline at end of file