hoanvd1210
hoanvd1210

Reputation: 147

Error when customize ValidationMessageFor

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

Answers (1)

Darin Dimitrov
Darin Dimitrov

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

Related Questions