i just about finished my first asp.net mvc site but i wasn't happy with the robustness of the validation.
i read up on validation and then added the below code to my Edit action in my UsersController:
if (user_.firstname.Trim().Length == 0)
{
ModelState.AddModelError("firstname", "First Name is required.");
return View();
}
i just did a test on this and i now am getting errors in my view where the Model is null.
<% using (Html.BeginForm())
{%>
<fieldset>
<legend>Fields</legend>
<p>
<label for="Email">
Login Name:
<%= Model.loginName%>
</label>
</p>
<p>
So in the above Model is null so i get an exception on Model.loginName. any idea whats going on here. If i remove the above code (the validation) everything works fine. (except that i can then put garbage in my database.