MODEL:
public class GuestResponse
{
[Required(ErrorMessage = "You must enter a name")]
public string Name { get; set; }
[Required(ErrorMessage = "Please enter your email address")]
[RegularExpression(".+\\@.+\\..+",
ErrorMessage = "Please enter a valid email address")]
public string Email { get; set; }
[Required(ErrorMessage = "Please enter your phone number")]
[RegularExpression("^[0-9]+$", ErrorMessage = "Only numbers are allowed")]
public string Phone { get; set; }
[Required(ErrorMessage = "Please specify whether you'll attend")]
public bool? WillAttend { get; set; }
}
VIEW:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>RsvpForm</title>
<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
</head>
<body>
<h1>RSVP</h1>
<%Html.EnableClientValidation(); %>
<% using(Html.BeginForm()) { %>
...
Gdje grijesim? Validacija jednostavno ne radi...
[IMG]http://img233.imageshack.us/img233/5078/thumbnailte1.th.jpg[/IMG]
They say I look like daddy :D