I have a lot of Guid
properties in my classes and I want to make sure that a Guid.Empty
will make ModelState
invalid. What's the best way of handling this?
Say, I have the following class that a user submits to my API action method:
{
public Guid Id { get; set: }
[Required]
public string name { get; set: }
}
By using [Required]
, I make sure that the user must always give me something in the name field but if the user doesn't provide an Id
, it becomes Guid.Empty
and ModelState
is still valid.
I want to make sure that I will always get a Guid
value in the Id
property and NOT a Guid.Empty
.