HtmlHelper.ValidationMessage Method (String, String)

Returns an HTML span element that contains a validation error message for the specified form field.

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


Public Function ValidationMessage ( _
    name As String, _
    message As String _
) As IHtmlString
Dim instance As HtmlHelper 
Dim name As String 
Dim message As String 
Dim returnValue As IHtmlString 

returnValue = instance.ValidationMessage(name, _
public IHtmlString ValidationMessage(
    string name,
    string message
IHtmlString^ ValidationMessage(
    String^ name, 
    String^ message
member ValidationMessage : 
        name:string * 
        message:string -> IHtmlString
public function ValidationMessage(
    name : String, 
    message : String
) : IHtmlString


  • name
    Type: System.String
    The name of the form field that was validated.
  • message
    Type: System.String
    The validation error message to display. If null reference (Nothing in Visual Basic), the first validation error message that is associated with the specified form field is displayed.

Return Value

Type: System.Web.IHtmlString
If the value in the specified field is valid, null reference (Nothing in Visual Basic); otherwise, the HTML markup that represents the validation error message that is associated with the specified field.


Exception Condition

name is null reference (Nothing in Visual Basic) or empty.


This method is used in conjunction with the System.Web.Helpers.Validation class.

The returned markup consists of an HTML span element in the following form:


message contains the specified validation error message, or the first validation error message that is associated with the form field whose id attribute is name if message is null reference (Nothing in Visual Basic). Additional validation errors might be associated with the field and will be returned the next time that the form is submitted if the errors have not been resolved.

See Also


HtmlHelper Class

ValidationMessage Overload

System.Web.WebPages.Html Namespace