Html.ValidationSummary() is still being rendered even if the model state is valid.
This example doesn't work:
<% if (!this.ViewData.ModelState.IsValid)
{ %>
<%= Html.ValidationSummary()%>
<% } %>
There is still an empty 'ul' tag being rendered. How do I make it render only if the ModelState is not valid?
EDIT Turns out the ModelState is really invalid, but my code does not add any error messages, it's just invalid for no obvious reason.
[AcceptVerbs("POST")]
public ActionResult Login(string username, string password, bool? remember)
{
if (string.IsNullOrEmpty(username))
{
ModelState.AddModelError("Username", "Username is required");
}
if (string.IsNullOrEmpty(password))
{
ModelState.AddModelError("Password", "Password is required");
}
if (ModelState.IsValid)
{
; // this point is never reached
}
return View();
}