I have a class called \'User\' and a property \'Name\'
public class User
{
[Required]
public string Name { get; set; }
}
And api co
The model should be an input parameter to your ActionMethod, and ModelState.IsValid will validate as per the attributes you set in the Model class, in this case as it is set [Required] it will be validated againg null values,
and if you just wish to manually check whether there is a value, you can check it directly.
if (user.Name == null) {
return;
}