Created
April 5, 2017 00:26
-
-
Save jwill9999/52c327c95ab885b8a4ce377c2bf1bb77 to your computer and use it in GitHub Desktop.
Adding Validation to Asp.net Mvc5 entity framework code first approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
****example****** | |
public class Movie | |
{ | |
public int ID { get; set; } | |
[StringLength(60, MinimumLength = 3)] | |
public string Title { get; set; } | |
[Display(Name = "Release Date")] | |
[DataType(DataType.Date)] | |
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] | |
public DateTime ReleaseDate { get; set; } | |
[RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$")] | |
[Required] | |
[StringLength(30)] | |
public string Genre { get; set; } | |
[Range(1, 100)] | |
[DataType(DataType.Currency)] | |
public decimal Price { get; set; } | |
[RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$")] | |
[StringLength(5)] | |
public string Rating { get; set; } | |
} | |
*****Instructions******* | |
Build solution then | |
add-migration DataAnnotations | |
update-database |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment