views:

84

answers:

1

Is there an easy way to get a summary string of the errors that have been added to a controller's modelstate?

I'm looking to return this in an Ajax method and want the validation errors etc to be returned to the client (i.e. the view does not exist for this method call).

Or do I have to loop through the modelstate and look at each object and extract the error text manually?

A: 

See if this helps:

ModelErrorCollection Class

I think that if you loop through the Items collection you can return the result you want.

ModelErrorCollection Members

ValidationExtensions.ValidationSummary Method

Leniel Macaferi
Thanks, but there is no view (it's an ajax callback method) so the htmlhelper methods aren't available. I'll go with looping through the Items collection.
David Moorhouse