Ok, I have a ViewModel that looks like this:
public class UserLogin
{
[Required]
public string EmailAddress { get; set; }
[Required]
public string Password { get; set; }
}
My controller is as follows:
[HttpPost]
public ActionResult LogIn(UserLogin model)
{
if (!ModelState.IsValid)
{
}
}
My view is as follows:
<% Html.BeginForm("Join", "User", FormMethod.Post); %>
<%= Html.Hidden("ReturnUrl", Request.Url.AbsolutePath) %>
<%= Html.TextBoxFor(c => c.EmailAddress, new { id = "join-emailaddress", @class = "text", uiHintText = "Email address" })%>
<%= Html.ValidationMessageFor(c => c.EmailAddress, "*") %>
<%= Html.PasswordFor(c => c.Password, new { id = "join-password", @class = "text", uiHintText = "Password" })%>
<%= Html.ValidationMessageFor(c => c.Password, "*")%>
<%= Html.PasswordFor(c => c.PasswordConfirm, new { id = "join-password-confirm", @class = "text", uiHintText = "Password (repeat)" })%>
<%= Html.ValidationMessageFor(c => c.PasswordConfirm, "*")%>
<input type="submit" value="Sign me up!" class="submit" />
<% Html.EndForm(); %>
If I submit the form without entering any of the fields, I sequentially get the value "true" for "ModelState.IsValid".
Should it be "false" since I marked these fields as "Required" and did not enter any values?
source
share