代码改变世界

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

2009-10-10 15:16  贺臣  阅读(1936)  评论(0编辑  收藏  举报
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);
      该方法生成普通文本输入框


作者:情缘
出处:http://www.cnblogs.com/qingyuan/
关于作者:从事仓库,生产软件方面的开发,在项目管理以及企业经营方面寻求发展之路
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
联系方式: 个人QQ  821865130 ; 仓储技术QQ群 88718955,142050808 ;
吉特仓储管理系统 开源地址: https://github.com/hechenqingyuan/gitwms