Error when customize ValidationMessageFor
- by user1542080
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));
}
}
}