views:

300

answers:

1

I'm finding it hard to find out helpful information about ASP.NET MVC's validation HTML helpers - Html.Validate and Html.ValidateFor.

Has anyone worked with these methods? what are they for?

+1  A: 

see this post for an answer

If there are situations where you don't actually want a validation message to visually appear for each field (i.e. by using Html.ValidationMessage), but would rather allow a summary to be the sole source of validation error messages (i.e. by using Html.ValidationSummary), you still need some way to "trigger" the validation to occur for the specific fields you want it to. This can be achieved by using the Html.Validate/Html.ValidateFor<> methods within your view. Those helpers won't render anything, but will simply register the specified field for client-side validation.

SQueek
Are they only for client side validation?
Shay Friedman
sorry, I couldn't say it to 100%. the documentation is not so precise about this. It only says as a remark to enable clientsidevalidation. but what about testing it quickly. I would think, that your validation is fired on the client and also on the server when posting back. because your validation rules are defined as property attributes. do you need client validation only? why then not use an jquery validation library ;-)
SQueek
I can't get it to work, too. I am to stupid to pass the right parameters. Could any pro help us? ...Shay, for what problem you intend to use this method?
SQueek
I got an answer at the asp.net site forums. Turned out that these methods are used only for client side validation and only works for "automatic validation" that is added by data annotations or metadata classes.
Shay Friedman