I am trying to trace through why my ASP.NET MVC 2 validation isn't working, but I cant find enough about HOW it works to be able to do this.
I have followed the steps in this useful article by David Hayden which seems to be the best documentation currently out there, but nothing actually happens.
I get validation when i submit to the server (as I did since Preview 1 when i added data annotations to my model) but I'm not getting any client side validation.
How can i trace through to test? So far I have verified the following obvious things
I cant see easily what is hooking up to which events to know quite how to debug it.
Validation is an important aspect in ASP.NET MVC applications. It is used to check whether the user input is valid. ASP.NET MVC provides a set of validation that is easy-to-use and at the same time, it is also a powerful way to check for errors and, if necessary, display messages to the user.
In ASP.NET MVC model validations are done using Data Annotation, its inherited System. ComponentModel. DataAnnotations assembly. In ASP.NET MVC 4 provides a different way to build custom validation.
Validation Message Tag Helper (asp-validation-for)It adds the data-valmsg-for="property name" attribute to the element which it carries for example span. It attaches the validation message on the input field of the specified Model property. The client-side validation can be done with jQuery.
By default, ASP.NET validation controls perform validation automatically when the page is posted back to the server, after page initialization (that is, after view-state and postback data have been processed) and before your event-handling code is called.
Here's what I've learnt:
MOST IMPORTANT
HOW IT WORKS (very simple overview)
MISC
I cannot seem to get validation working when I have a partial control, if that control uses a different model from the view that defines the Form.
You do NOT need to use Html.TextBoxFor or Html.ValidationMessageFor, you can use Html.TextBox and Html.ValidationMessage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With