Skip to Main Content
ASP.NET 4 24-Hour Trainer
book

ASP.NET 4 24-Hour Trainer

by Toi B. Wright
July 2010
Beginner content levelBeginner
552 pages
10h 14m
English
Wrox
Content preview from ASP.NET 4 24-Hour Trainer

Chapter 16B. Validation Helpers in MVC

Your web application must verify that all of the data entered by users is valid. This once formidable task has been made easier by a special class of HTML helpers that support validating input from an HTML form. Most of these special HTML helpers are members of the ValidationExtensions class. In this lesson I show you how to use the validation helpers provided by the ASP.NET MVC framework.

VALIDATION HELPERS

These are the validation helpers that are included as part of the ASP.NET MVC framework:

  • Html.EnableClientValidation() — This method enables client-side validation.

  • Html.Validate() — This method retrieves the validation metadata for the given model and applies each rule.

  • Html.ValidateFor() — This method retrieves the validation metadata for the given strongly-typed object and applies each rule.

  • Html.ValidationMessage() — This method displays the error message if an error exists for a given field.

  • Html.ValidationMessageFor() — This method displays all of the error messages associated with a strongly-typed object.

  • Html.ValidationSummary() — This method returns a bulleted list of all of the errors in the ModelStateDictionary object.

    Warning

    To enable client-side validation, you must add this line of code

    <% Html.EnableClientValidation(); %>

    before

    <% using (Html.BeginForm()) {%>

    and your page must refer to the following three files from the Scripts folder:

    <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript" /> <script src="../../Scripts/jquery.validate.js" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 4 24-Hour Trainer

ASP.NET 4 24-Hour Trainer

Toi B. Wright
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9780470596913Purchase bookExamplesErrata