//Created a static method which accepts name, value and htmlAttributes as parameter. This method is extension method. //We can access this method using @html. public static HtmlString Custom_TextArea(this HtmlFileHelper helper, string name, string value, object htmlAttributes) { //Created a textarea tag using TagBuilder class. TagBuilder textarea = new TagBuilder("textarea"); //Setting its name attribute textarea.Attributes.Add("name", name); if (!string.IsNullOrEmpty(value)) { //assigning the value passed as parameter. This valus is shown inside the TextArea. textarea.InnerHtml = value; } //Merging the attribute object. textarea.MergeAttributes(new RouteValueDictionary(htmlAttributes)); return(MvcHtmlString.Create(textarea.ToString())); }
//Created a static method which accepts name and value as parameter. This method is extension method. //We can access this method using @html. //This method in turn calls another method which is our third overload. public static HtmlString Custom_TextArea(this HtmlFileHelper helper, string name, string value) { return(Custom_TextArea(helper, name, value, null)); }