zoukankan      html  css  js  c++  java
  • 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);
          该方法生成普通文本输入框
  • 相关阅读:
    Python全栈day19(函数补充)
    Python全栈day18(三元运算,列表解析,生成器表达式)
    Python全栈day18(迭代器协议和for循环工作机制)
    KVM虚拟化
    Python使用函数实现把字符串转换成整数
    MySQL备份1356错误提示修复办法
    Python全栈day17(文件处理)
    CentOS添加PHP至环境变量
    CentOS7.2编译配置LNMP环境(MySQL5.7.20,PHP7.0.24)
    php查询mysql数据库 查询条件替中文字符串变量时无法查询
  • 原文地址:https://www.cnblogs.com/qingyuan/p/1580316.html
Copyright © 2011-2022 走看看