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

Returns an HTML span element that has the specified custom attributes defined by an attribute dictionary, and that contains the first validation error message for the specified form field.

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

Syntax

'Declaration
Public Function ValidationMessage ( _
    name As String, _
    htmlAttributes As IDictionary(Of String, Object) _
) As IHtmlString
'Usage
Dim instance As HtmlHelper 
Dim name As String 
Dim htmlAttributes As IDictionary(Of String, Object)
Dim returnValue As IHtmlString 

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

Parameters

  • name
    Type: System.String
    The name of the form field that was validated.

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.

Exceptions

Exception Condition
ArgumentException

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

Remarks

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:

<span ...htmlAttributes...>message</span>

message contains the first validation error message that is associated with the form field whose id attribute is name. 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

Reference

HtmlHelper Class

ValidationMessage Overload

System.Web.WebPages.Html Namespace