MVC进阶学习--HtmlHelper控件解析(二)

1.InputExtensions类
      InputExtensions类主要有5种类型的扩展方法,分别用于CheckBox控件,Hidden控件,Pass控件,RadionButton控件,TextBox控件

2.CheckBox控件
      有如下重载方法:
      CheckBox(string name);
      CheckBox(string name,bool isChecked);
      CheckBox(string name,book isChecked,object htmlAttributes);
      CheckBox(string name,object htmlAttributes);
      CheckBox(string name,IDictionary<string ,object> htmlAttributes);
      CheckBox(string name,book isChecked,IDictionary<string ,object> htmlAttributes);
      例子:
      页面代码 
Code
      生成页面之后的html代码如下:
      
Code

      对比上面的代码我们发现,<%=Html.CheckBox()%> 除了生产CheckBox标签之外还生成了一个隐藏的表单域,他和Checkbox具有相同的name。
      
      处理表单的aciton
Code
      通过表单集合FormCollection的索引或键,可以获取复选框的状态字符串,如果选中则得到值为"true,false",
      如果没有选中得到的值为"false",这里得到两个值是因为Checkbox还有一个对应的隐藏控件

3.RadionButton控件
      RadionButton(string name,object value);
      RadionButton(string name,object value,object htmlAttributes);
      RadionButton(string name,object value,IDictionary<string,object> htmlAttributes);
      RadionButton(string name,object value,bool isChecked);
      RadionButton(string name,object value,bool isChecked,object htmlAttributes);
      RadionButton(string name,object value,bool isChecked,IDictionary<string,object> htmlAttributes);
      这里不同Checkbox,不会生成隐藏的表单域,action中得到的值也不是True false,而是设置的值,这里不再详细讲解
Code

3.Hidden控件
      Hidden(string name);
      Hidden(string name,object value);
      Hidden(string name,object value,object htmlAttrbutes);
      Hidden(string name,object value,IDictionary<string ,object> htmlAttributes);
      该方法生产隐藏表单域
      
4.PassWord控件
      Password(string name);
      Password(string name,object value);
      Password(string name,object value,object htmlAttrbutes);
      Password(string name,object value,IDictionary<string ,object> htmlAttributes);
      该方法生成PassWord输入框

5.TextBox控件
      TextBox(string name);
      TextBox(string name,object value);
      TextBox(string name,object value,object htmlAttrbutes);
      TextBox(string name,object value,IDictionary<string ,object> htmlAttributes);
      该方法生成普通文本输入框

你可能感兴趣的:(html)