有时候我们需要的控件并不在
- Html.ActionLink()
- Html.BeginForm()
- Html.CheckBox()
- Html.DropDownList()
- Html.EndForm()
- Html.Hidden()
- Html.ListBox()
- Html.Password()
- Html.RadioButton()
- Html.TextArea()
- Html.TextBox()
首先什么是扩展类,简单点就是对一个类进行扩展,那如何实现扩展的呢,通过看王清培写的
.net 模式 框架 工具中有个链式编程的玩意,扩展类就是这个。
不过这个是视图的扩展类,所以在编写这个扩展类的时候,命名空间一定要写
namespace System.Web.Mvc
至于方法的编写,都是类似于
public static string Calendar(this HtmlHelper helper, string name)
这种结构的方法。
扩展HTML控件有个问题就是绑定模型之后没法提交数据,这里采用的方式是通过提交基本数据类型设置控件的name属性提交信息的方式提交的