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);
          该方法生成普通文本输入框
  • 相关阅读:
    EF6的DbContext动态连接字符串
    Swagger配置
    Xamarin学习资源收集
    xmarin开发问题收集
    javascript基础
    Vue3.0到底带来来哪些变化视频笔记1
    Git操作
    EFCore 通过数据库生成模型
    Web Deploy远程发布
    ASP.NET CORE系列【七】分析NetCore启动原理
  • 原文地址:https://www.cnblogs.com/qingyuan/p/1580316.html
Copyright © 2011-2022 走看看