Reputation: 147
i want to customize ValidationMessageFor which display error. when i run application, a get an error : No overload for method 'ValidationMessageFor' takes 1 arguments
I'm understand my error, but i don't know how to fix it ? I need some suggest . Thanks you for reading!
My code :
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
namespace OurCompanyUI.app_code
{
public static class MyHtml
{
public static MvcHtmlString ValidationMessageFor<TModel, TProperty>(
this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression,
string validationMessage,
IDictionary<string, Object> htmlAttributes
)
{
string modelName = ExpressionHelper.GetExpressionText(expression);
TagBuilder p = new TagBuilder("p");
p.InnerHtml = htmlHelper.ValidationMessageFor(htmlHelper,expression).ToString();
// p.InnerHtml = htmlHelper.ValidationMessageFor().ToString();
return MvcHtmlString.Create(p.ToString(TagRenderMode.Normal));
}
}
}
Upvotes: 0
Views: 1679
Reputation: 1038720
Make sure you have brought the namespace into which the original ValidationMessageFor
helper is defined into scope by adding the following to your using directives:
using System.Web.Mvc.Html;
Upvotes: 2