MvcValidatorToolkit/Extensions/ControllerExtensions.cs
/// <summary>
/// Validates the HTML form data (Request.Form) using the validation set defined for the 
/// calling controller action. This mehtod must be called within a controller action.
/// </summary>
Validates the HTML form data (Request.Form) using the validation set defined for the
calling controller action. This mehtod must be called within a controller action.
Validates the HTML form data ( Request . Form ) using the validation set defined for the calling controller action . This mehtod must be called within a controller action .
public static bool ValidateForm(this Controller controller)
		{
			StackTrace st = new StackTrace(false);
			StackFrame fr = st.GetFrame(1);
			MethodBase mb = fr.GetMethod();
			ValidationSetAttribute[] attributes = (ValidationSetAttribute[])mb.GetCustomAttributes(typeof(ValidationSetAttribute), false);
			if(attributes.Length == 0)
				throw new Exception("The ValidateForm method expects a ValidationSetAttribute defined for the calling controller action");
			if(attributes.Length > 1)
				throw new Exception("The ValidateForm method expects just one ValidationSetAttribute defined for the calling controller action");
			ValidationSet vs = attributes[0].ValidationSet;
			return ValidateForm(controller, vs);
		}
public static bool ValidateForm ( this Controller controller ) { StackTrace st = new StackTrace ( false ) ; StackFrame fr = st . GetFrame ( 1 ) ; MethodBase mb = fr . GetMethod ( ) ; ValidationSetAttribute [ ] attributes = ( ValidationSetAttribute [ ] ) mb . GetCustomAttributes ( typeof ( ValidationSetAttribute ) , false ) ; if ( attributes . Length == 0 ) throw new Exception ( " " ) ; if ( attributes . Length > 1 ) throw new Exception ( " " ) ; ValidationSet vs = attributes [ 0 ] . ValidationSet ; return ValidateForm ( controller , vs ) ; }
Validates the HTML form data (Request.Form) using the validation set defined for the
calling controller action.
Validates the HTML form data ( Request . Form ) using the validation set defined for the calling controller action .
// Get method data for calling method (should be a controller action) // Get the validation set attribute // Stop processing if not exactly one validation set is defined // Get instance of the validation set class
Controller
this