Export (0) Print
Expand All

ValidationExtensions.ValidationMessage Method (HtmlHelper, String, IDictionary<String, Object>)

Displays a validation message if an error exists for the specified field in the ModelStateDictionary object.

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

public static string ValidationMessage(
	this HtmlHelper htmlHelper,
	string modelName,
	IDictionary<string, Object> htmlAttributes
)

Parameters

htmlHelper
Type: System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
modelName
Type: System.String
The name of the property or model object that is being validated.
htmlAttributes
Type: System.Collections.Generic.IDictionary<String, Object>
An object that contains the HTML attributes for the element.

Return Value

Type: System.String
If the property or object is valid, an empty string; otherwise, a span element that contains an error message.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type HtmlHelper. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

The ValidationMessage method renders a validation message if the specified field contains incorrect input.

If the DefaultModelBinder instance cannot bind a form-field value to the model, it adds an error to the ModelState object. When the form is rendered, the validation messages and validation summary are displayed based on the Errors property of the ModelState object.

Community Additions

Show:
© 2014 Microsoft