接上篇…現在讓我們開始討論如何創建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
}