You can extend the HtmlHelper as:
public static class CustomHtmlHelper {
public static string ValidationImage(this HtmlHelper helper, string name) {
if (helper.ViewData.ModelState[name] == null || helper.ViewData.ModelState[name].Errors == null) {
return String.Empty;
}
TagBuilder tag = new TagBuilder("img");
tag.Attributes.Add("src", "Error.gif");
tag.Attributes.Add("alt", "Error");
tag.Attributes.Add("title", helper.ViewData.ModelState[name].Errors[0].ErrorMessage);
return tag.ToString(TagRenderMode.SelfClosing);
}
}
Then on your page, import the class containing the extension method
<%@ Import Namespace="CustomHtmlHelperNamespace" %>
Then add the following to your page:
<label for="Name">Name:</label>
<%= Html.TextBox("Name")%>
<% Html.ValidationImage("Name") %>
HtmlHelper , HtmlHelper, ViewState , ( "" ), , HTML-, . title ""