Validation attributes make enforcing these requirements much simpler and easier to use.
Below is an annotated model from an app that stores information about movies and TV shows.
See a complete demo @Codepen The messages parameter is optional.
Before templates to create a reusable UI, you really only had the options of user controls or writing your own Html helpers, the former will almost certainly mean a compromise.
I believe the templating feature will assist in the goals of separation of concerns and being DRY.
In the second, it is an Array List, so that you can attach multiple files.
If you are using this in a Windows forms project, you must add a reference to System. See the comments for full details.'TWO FUNCTIONS 'SAME EXCEPT FIRST TAKES A STRING FOR ATTACHMENT 'SECOND TAKES AN ARRAY LIST SO YOU CAN SEND MULTIPLE 'ATTACHMENTS 'FROM: Email address FRom 'TO: EMAIL address To 'Subject: Subject; Body: Message Text 'Optional CC, BCC: CC and bcc recipients 'SMTPSERVER: Optional, if not specified 'local machine is used 'Attachment File (first function: Optional, file name) 'Attachment Files (second function: Optional, list of 'attachments in form of an array list) Public Sub Send Mail One Attachment(By Val From As String, _ By Val send To As String, By Val Subject As String, _ By Val Body As String, _ Optional By Val Attachment File As String = "", _ Optional By Val CC As String = "", _ Optional By Val BCC As String = "", _ Optional By Val SMTPServer As String = "") Dim my Message As Mail Message Try my Message = New Mail Message() With my Message .
Using a library to do form validation can save lots of your development time. j Query Form validation library is the most popular validation library.
This post collects all my notes and references on j Query Form validation library.
However, You should always customize the validation error messages.
If you imagine form as a dialog between your website and your user, the messages play an important role.
Don’t leave it to the auto-generated default messages.
Explain to your user what is wrong and suggest solutions.
If you don’t know what strongly typed Html helpers are I recommend you read Scott Gu’s excellent post first.