Entity Framework - Validation (server + clientside, jquery) with data annotations, WITHOUT MVC?

You've probably found a solution or moved on by now, but I created an open source project that does exactly this - MVC style validation with Data Annotations attributes and jQuery Validate xvalwebforms.codeplex.com You'll be interested in the jQuery. Validate branch. Its not quite complete yet, but very close.

Here's an example from the demo project: Model public class Booking : IValidatableObject { Required(ErrorMessage = "Client name is required. ") StringLength(15, ErrorMessage = "Client name must be less than 15 characters. ") public string ClientName { get; set; } Range(1, 20, ErrorMessage = "Number of guests must be between 1 and 20.") public int NumberOfGuests { get; set; } Required(ErrorMessage = "Arrival date is required.

") DataType(DataType. Date, ErrorMessage = "Arrival date is invalid.") public DateTime ArrivalDate { get; set; } Required(ErrorMessage = "Smoking type is requried. ") public SmokingType SmokingType { get; set; } Required(ErrorMessage = "Email address is required.

") DataType(DataType. EmailAddress, ErrorMessage = "Email address is invalid. ") public string EmailAddress { get; set; } #region IValidatableObject Members public IEnumerable Validate(ValidationContext validationContext) { if (ArrivalDate == DateTime.

MinValue) { yield return new ValidationResult("Arrival date is required.", new {"ArrivalDate"}); } // Business rule: Can't place bookings on Sundays if (ArrivalDate. DayOfWeek == DayOfWeek. Sunday) { yield return new ValidationResult("Bookings are not permitted on Sundays.", new {"ArrivalDate"}); } } #endregion } ASPX Markup fieldset class="booking"> Booking Your name: Number of guests: Arrival date: Email address: Text, NumberOfGuests = Convert.

ToInt32(txtNumberOfGuests. Text), ArrivalDate = Convert. ToDateTime(txtArrivalDate.

Text), EmailAddress = txtEmailAddress. Text }; BookingManager. PlaceBooking(booking); }.

You've probably found a solution or moved on by now, but I created an open source project that does exactly this - MVC style validation with Data Annotations attributes and jQuery Validate. xvalwebforms.codeplex.com You'll be interested in the jQuery. Validate branch.

Its not quite complete yet, but very close. Here's an example from the demo project: Model public class Booking : IValidatableObject { Required(ErrorMessage = "Client name is required. ") StringLength(15, ErrorMessage = "Client name must be less than 15 characters.") public string ClientName { get; set; } Range(1, 20, ErrorMessage = "Number of guests must be between 1 and 20.

") public int NumberOfGuests { get; set; } Required(ErrorMessage = "Arrival date is required. ") DataType(DataType. Date, ErrorMessage = "Arrival date is invalid.

") public DateTime ArrivalDate { get; set; } Required(ErrorMessage = "Smoking type is requried. ") public SmokingType SmokingType { get; set; } Required(ErrorMessage = "Email address is required.") DataType(DataType. EmailAddress, ErrorMessage = "Email address is invalid.

") public string EmailAddress { get; set; } #region IValidatableObject Members public IEnumerable Validate(ValidationContext validationContext) { if (ArrivalDate == DateTime. MinValue) { yield return new ValidationResult("Arrival date is required. ", new {"ArrivalDate"}); } // Business rule: Can't place bookings on Sundays if (ArrivalDate.

DayOfWeek == DayOfWeek. Sunday) { yield return new ValidationResult("Bookings are not permitted on Sundays. ", new {"ArrivalDate"}); } } #endregion } ASPX Markup Booking Your name: Number of guests: Arrival date: Email address: Code behind protected void btnSubmit_Click(object sender, EventArgs e) { if (!IsValid) { return; } if (txtNumberOfGuests.Text.

Length == 0) { txtNumberOfGuests. Text = "1"; } Booking booking = new Booking { ClientName = txtClientName. Text, NumberOfGuests = Convert.

ToInt32(txtNumberOfGuests. Text), ArrivalDate = Convert. ToDateTime(txtArrivalDate.

Text), EmailAddress = txtEmailAddress. Text }; BookingManager. PlaceBooking(booking); }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions