I’m trying to validate a basic form, can i not use the standard validation controls? Everywhere i’m looking seems to try and use something like the below
<%= Html.ValidationSummary() %> <% using (Html.BeginForm()) {%> <fieldset class='fields'> <legend>Create New Contact</legend> <p> <label for='task'>Task Name:</label> <%= Html.TextBox('task') %> <%= Html.ValidationMessage('task', '*') %> </p> <p class='submit'> <input type='submit' value='Create' /> </p> </fieldset> <% } %>
I thought id be able to use the standard components? Any pointers would be brilliant!
ASP.NET MVC uses pretty-much a completely different philosophy to regular ASP.NET; as such, with a few minor exceptions, almost no ASP.NET controls (etc) will work in ASP.NET MVC. Apart from anything else, the point in the page life-cycle where they usually do something simply doesn’t exist.
There are ways of doing this, for example in jQuery validation plug-in, or by using
IDataErrorInfo, etc.Note that if you do validation at the client you must still do it (separately) at the server. Those pesky browsers can’t be trusted ;-p