User-893317190 posted
Hi john_mm,
decimal is a simple type which couldn't be null, so the required attribute doesn't work.
If you want it to be null, please change decimal to decimal?, which will allow null value, then your Required will work when the value of Bedget is null.
Below is my test code.
My model
public class Movie
{
public int Id { get; set; }
[StringLength(60,MinimumLength =3)]
[Required(ErrorMessage ="need title")]
public string Title { get; set; }
[DataType(DataType.Date)]
public DateTime? ReleaseDate { get; set; }
public string Genre { get; set; }
//[Range(1,100)]
[DataType(DataType.Currency)]
[Required(ErrorMessage = "Value cant empty")]
public decimal? Price { get; set; }
}
cshtml.
<div class="col-md-4">
<form asp-action="Create">
@* other fields are ommited *@
<div class="form-group">
<label asp-for="Price" class="control-label"></label>
<input asp-for="Price" class="form-control" />
<span asp-validation-for="Price" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
The result.

Best regards,
Ackerly Xu