Skip to content

Commit 2310b6e

Browse files
vanillajonathanthinkingserious
authored andcommitted
Add [EmailAddress] attribute (#876)
* Add [EmailAddress] attribute * Validate model state
1 parent 56da7a9 commit 2310b6e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ExampleNet45ASPNetProject/SendGrid.ASPSamples/Controllers/EmailController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public ActionResult Send()
2323
[HttpPost]
2424
public ActionResult Send(EmailContract emailContract)
2525
{
26+
if (!ModelState.IsValid)
27+
{
28+
return View(model);
29+
}
30+
2631
try
2732
{
2833
var response= _sendGridEmailService.Send(emailContract);
@@ -37,4 +42,4 @@ public ActionResult Send(EmailContract emailContract)
3742
}
3843

3944
}
40-
}
45+
}

ExampleNet45ASPNetProject/SendGrid.ASPSamples/Models/EmailContract.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,30 @@ public class EmailContract
1010
{
1111
[Required]
1212
[Display(Name = "From Email Address")]
13+
[EmailAddress]
1314
public string FromEmailAddress { get; set; }
1415

1516
public string Alias { get; set; }
1617

1718
[Required]
1819
[Display(Name = "To Email Address")]
20+
[EmailAddress]
1921
public string ToEmailAddress { get; set; }
22+
2023
[Display(Name = "Cc Email Address")]
24+
[EmailAddress]
2125
public string CcEmailAddress { get; set; }
26+
2227
[Display(Name = "Bcc Email Address")]
28+
[EmailAddress]
2329
public string BccEmailAddress { get; set; }
30+
2431
[Required]
2532
[Display(Name = "Subject")]
2633
public string Subject { get; set; }
34+
2735
[Required]
2836
[Display(Name = "Body")]
2937
public string Body { get; set; }
3038
}
31-
}
39+
}

0 commit comments

Comments
 (0)