Share via


Controller.TryValidateModel Method (Object)

Validates the specified model instance.

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Syntax

'Declaration
Protected Friend Function TryValidateModel ( _
    model As Object _
) As Boolean
protected internal bool TryValidateModel(
    Object model
)
protected public:
bool TryValidateModel(
    Object^ model
)

Parameters

Return Value

Type: System.Boolean
true if the model validation is successful; otherwise, false.

Remarks

When a model is being validated, all validators for all properties are run if at least one form input is bound to a model property.

The TryValidateModel is like the ValidateModel method except that the TryValidateModel method does not throw an InvalidOperationException exception if the model validation fails.

For more information model validation, see the entry Input Validation vs. Model Validation in ASP.NET MVC on Brad Wilson's blog.

See Also

Reference

Controller Class

TryValidateModel Overload

System.Web.Mvc Namespace