Here is my model:
public sealed class UserModel
{
[Key]
[Required]
[StringLength(20, MinimumLength = 4)]
public string Username { get; set; }
[Required]
[EmailAddress]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
[StringLength(20, MinimumLength = 4)]
public string Password { get; set; }
public bool IsValid { get; set; }
}
Username, Email, and Password are provided by the user, however IsValid should only be modified by the server, in other words if the user provides true the server should return BAD REQUEST or not take this value into account.
So, I could set the property to false on model creation, but it is not clean.
Is there a way to make a property private or "server only"?
[2018-04-01]:
I found a nice article where [BindNever] was used, sadly it does not work with data coming [FromBody] as pointed here. So for the moment I just set the property to false in the POST handler by myself but it is very ugly therefore I'm still looking for other ways to do it!
[2018-04-02]: Finally found ! Check this out !
publictoprivate?