Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
MVC 3-RAZOR Validation
1. MVC 3-RAZOR-Validations
Krunal Trivedi
Corporate Trainer DotNet,Silverlight,SPS 2010, SharePoint 15,MVC , Windows
Phone , Windows 8
MCT S For .NET Web Technology
MCTS For SharePoint Server 2010 Development
Co-Founder at Aavid Technologies
Email:krunaltrivedi@live.in
Contact : 09998472789
24. • In this case , it is not possible to display Property-Level
validation messages.
• Suppose , we want to display both Property-Level validation
messages and model-level validation messages.
• Let’s try…
29. Client-Side Validation
• The MVC Framework supports unobtrusive client-side
validation.
• The term unobtrusive means that validation rules are
expressed using attributes added to the HTML elements that
we generate.
• These are interpreted by a JavaScript library that is included
as part of the MVC Framework .
30. Unobstrusive means….3 things
• The first is that the JavaScript that performs the validation
is kept separate from the HTML elements, which means we
don’t have to include client-side validation logic into our views
and that the HTML we generate is easier to read.
31. • The second characteristic is that the validation is performed
using progressive enhancement.
• This means that if a user’s browser doesn’t support all of the
JavaScript features we require for client-side validation, then
the validation will be performed using simpler techniques.
• For example, if the user has disabled JavaScript, then server-
side validation will be seamlessly performed without the user
being otherwise penalized (no unpleasant error messages or
special steps to take).
32. • The third characteristic is a set of best practices to mitigate
the effect of browser inconsistencies and behaviors.
37. The order in which the jQuery files are referenced is significant.
If you change the order, you will find
that the client validation is not performed.
• The scripts folder contains two versions of each JavaScript
library.
• The versions whose name ends with min.js are the minimized
versions, meaning that all of the whitespace, comments, and
other nonessential content have been removed to reduce the
size of the library file.
• The minimized files can be much smaller and are typically
used in production to reduce the amount of data that the
client downloads.
• During development, the unminimized versions are typically
used so that the JavaScript can be debugged (or just read) if
problems arise.
42. How it works !!!
• One of the benefits of using the MVC Framework client-side
validation feature is that we don’t have to write any
JavaScript. Instead, the validation rules are expressed using
HTML attributes. Here is the
• HTML that is rendered by the Html.EditorFor helper for the
ClientName property when client-side
• validation is disabled:
49. • The MVC client-side validation support doesn’t generate any
JavaScript or JSON data to direct the validation process; like
much of the rest of the MVC Framework, we rely on
convention.
• The first attribute that was added is data-val. The jQuery
Validation library identifies those fields that require validation
by looking for this attribute.
• Individual validation rules are specified using an attribute in
the form data-val-<name>, where name is the rule to be
applied. So, for example, the Required attribute
50. • The interpretation of the required and length validation rules
is provided by the jQuery Validation library, on which the MVC
client validation features are built.
51. • The MVC client-validation features are built on top of the
jQuery Validation library, and if you prefer, you can use the
Validation library directly and ignore the MVC features.