I have a login page, in the page model there is a property called LoginDTO (custom class of mine). Within this are only two strings - username and password.
On the login page I have a login form with two fields, you can probably guess what they are. The code is here:
<div class="form-group">
<input class="form-control" type="email" name="email" placeholder="Email" asp-for="LoginDTO.Username">
</div>
<div class="form-group">
<input class="form-control" type="password" name="password" placeholder="Password" asp-for="LoginDTO.Password">
</div>
I fill out the input fields and hit submit (form method set as POST
, I have an OnPost
method in the page model to handle it), for some reason LoginDTO.Username
is null however LoginDTO.Password
is populated?? Therefore, of course, the ModelState is invalid and there is no Username
string to use.
How can this be? I've tried renaming the variable and setting it as value="@Model.LoginDTO.Username"
instead of using asp-for
, neither made any difference.
Can anyone help?
UPDATE: I changed the Username
property to Email
and it's now started working?! Why do the name of these properties affect if they can be assigned values?!?!