首页 / 网页编程 / ASP.NET / 使用自定义ViewHelper来简化Asp.net MVC view的开发 - part3
        
            使用自定义ViewHelper来简化Asp.net MVC view的开发 - part32011-08-06 博客园 译:CareySon接上篇…现在让我们开始讨论如何创建HtmlHelper扩展方法.在前面我们说到了创建HtmlText类的方方面面。包括为HtmlText创建的扩展方法.这些扩展方法包括直 接被View调用的那些扩展方法。下面代码展示了HtmlText的几种不同的构造函数:public static class HtmlHelperExtensions
{
   #region Textbox
   public static IViewObject NewText(
     this HtmlHelper htmlHelper, string name)
   {
     return NewText(htmlHelper, name, null);
   }
   public static IViewObject NewText(
     this HtmlHelper htmlHelper, string name, string labelText)
   {
     return NewText(htmlHelper, name, labelText, null);
   }
   public static IViewObject NewText(
     this HtmlHelper htmlHelper, string name, string labelText, object value) 
   {
     return NewText(htmlHelper, name, labelText, value, null, false, true,  null);
   }
   public static IViewObject NewText(
     this HtmlHelper htmlHelper, string name, string labelText, object  value,
     string validationMessage, bool @readonly, bool createLi, object  attributes)
   {
     IViewObject viewObject = new HtmlText(
       new ViewRequestContext(htmlHelper), name, labelText, value,
       validationMessage, @readonly, createLi, attributes);
     viewObject.StartView();
     return viewObject;
   }
   #endregion
   //NOTE: SOME CONTENT OMITTED FROM THIS SNIPPET
}