public static IHtmlString ValidationMessage <TModel>(this HtmlHelpers <TModel> htmlHelper, string propertyName) { var errorsForField = htmlHelper.GetErrorsForProperty(propertyName).ToList(); if (!errorsForField.Any()) { return(new NonEncodedHtmlString(String.Empty)); } return(new NonEncodedHtmlString(errorsForField.First().GetMessage(propertyName))); }
private static IHtmlString InputHelper <TModel>(HtmlHelpers <TModel> htmlHelper, string inputType, string propertyName, string value, string className, string placeholder) { bool hasError = htmlHelper.GetErrorsForProperty(propertyName).Any(); return(new NonEncodedHtmlString(String.Format(InputTemplate, inputType, propertyName, propertyName, value, hasError ? String.Format("{0} {1}", className, "error").Trim() : className, placeholder))); }