fix validation snippets /6/ra (#23183)
* fix validation snippets /6/ra * fix validation snippets /6/rapull/23185/head
parent
53ed05388e
commit
e596cce731
|
@ -38,6 +38,6 @@ namespace RazorPagesMovie.Models
|
|||
[Required]
|
||||
public string Rating { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#define MovieDateRatingDA
|
||||
//#define MovieDateRatingDA
|
||||
#if MovieDateRatingDA
|
||||
#region snippet1
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
@ -37,6 +37,6 @@ namespace RazorPagesMovie.Models
|
|||
[Required]
|
||||
public string Rating { get; set; } = string.Empty;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//#define COMBINED
|
||||
#define COMBINED
|
||||
#if COMBINED
|
||||
#region snippet1
|
||||
using System;
|
||||
|
@ -12,21 +12,21 @@ namespace RazorPagesMovie.Models
|
|||
public int ID { get; set; }
|
||||
|
||||
[StringLength(60, MinimumLength = 3)]
|
||||
public string Title { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
[Display(Name = "Release Date"), DataType(DataType.Date)]
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
|
||||
[RegularExpression(@"^[A-Z]+[a-zA-Z\s]*$"), Required, StringLength(30)]
|
||||
public string Genre { get; set; }
|
||||
public string Genre { get; set; } = string.Empty;
|
||||
|
||||
[Range(1, 100), DataType(DataType.Currency)]
|
||||
[Column(TypeName = "decimal(18, 2)")]
|
||||
public decimal Price { get; set; }
|
||||
|
||||
[RegularExpression(@"^[A-Z]+[a-zA-Z0-9""'\s-]*$"), StringLength(5)]
|
||||
public string Rating { get; set; }
|
||||
public string Rating { get; set; } = string.Empty;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@ The `DataAnnotations` namespace provides:
|
|||
|
||||
Update the `Movie` class to take advantage of the built-in `[Required]`, `[StringLength]`, `[RegularExpression]`, and `[Range]` validation attributes.
|
||||
|
||||
[!code-csharp[](~/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie30/Models/MovieDateRatingDA.cs?name=snippet1)]
|
||||
[!code-csharp[](~/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie60/Models/MovieDateRatingDA.cs?name=snippet1)]
|
||||
|
||||
The validation attributes specify behavior to enforce on the model properties they're applied to:
|
||||
|
||||
|
@ -121,7 +121,7 @@ When validation logic needs to change, it's done only in the model. Validation i
|
|||
|
||||
Examine the `Movie` class. The `System.ComponentModel.DataAnnotations` namespace provides formatting attributes in addition to the built-in set of validation attributes. The `[DataType]` attribute is applied to the `ReleaseDate` and `Price` properties.
|
||||
|
||||
[!code-csharp[](razor-pages-start/sample/RazorPagesMovie/Models/MovieDateRatingDA.cs?highlight=2,6&name=snippet2)]
|
||||
[!code-csharp[](razor-pages-start/sample/RazorPagesMovie60/Models/MovieDateRatingDA.cs?highlight=2,6&name=snippet2)]
|
||||
|
||||
The `[DataType]` attributes provide:
|
||||
|
||||
|
@ -168,7 +168,7 @@ It's a best practice to avoid compiling hard dates in models, so using the `[Ran
|
|||
|
||||
The following code shows combining attributes on one line:
|
||||
|
||||
[!code-csharp[](razor-pages-start/sample/RazorPagesMovie30/Models/MovieDateRatingDAmult.cs?name=snippet1)]
|
||||
[!code-csharp[](razor-pages-start/sample/RazorPagesMovie60/Models/MovieDateRatingDAmult.cs?name=snippet1)]
|
||||
|
||||
[Get started with Razor Pages and EF Core](xref:data/ef-rp/intro) shows advanced EF Core operations with Razor Pages.
|
||||
|
||||
|
@ -176,7 +176,7 @@ The following code shows combining attributes on one line:
|
|||
|
||||
The DataAnnotations applied to the class changes the schema. For example, the DataAnnotations applied to the `Title` field:
|
||||
|
||||
[!code-csharp[](razor-pages-start/sample/RazorPagesMovie30/Models/MovieDateRatingDA.cs?name=snippet11)]
|
||||
[!code-csharp[](razor-pages-start/sample/RazorPagesMovie60/Models/MovieDateRatingDA.cs?name=snippet11)]
|
||||
|
||||
* Limits the characters to 60.
|
||||
* Doesn't allow a `null` value.
|
||||
|
@ -266,7 +266,7 @@ The `DataAnnotations` namespace provides:
|
|||
|
||||
Update the `Movie` class to take advantage of the built-in `[Required]`, `[StringLength]`, `[RegularExpression]`, and `[Range]` validation attributes.
|
||||
|
||||
[!code-csharp[](~/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie60/Models/MovieDateRatingDA.cs?name=snippet1)]
|
||||
[!code-csharp[](~/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie30/Models/MovieDateRatingDA.cs?name=snippet1)]
|
||||
|
||||
The validation attributes specify behavior to enforce on the model properties they're applied to:
|
||||
|
||||
|
|
Loading…
Reference in New Issue