一步一步封装自己的HtmlHelper组件BootstrapHelper(二(5)

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace BootstrapExtensions { public static class CheckBoxExtensions { /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>name属性</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string name) { return CheckBox(html, null, name, null, null, null, false, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name) { return CheckBox(html, id, name, null, null, null, false, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>是否选中</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, bool isCheck) { return CheckBox(html, id, name, null, null, null, isCheck, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>input的value值</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, object value) { return CheckBox(html, id, name, value, null, null, false, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>input的value值</param> /// <param>显示文本</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, object value, string text) { return CheckBox(html, id, name, value, text, null, false, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>input的value值</param> /// <param>显示文本</param> /// <param>是否选中</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, object value, string text, bool isCheck) { return CheckBox(html, id, name, value, text, null, isCheck, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>input的value值</param> /// <param>显示文本</param> /// <param>label标签的样式</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, object value, string text, string labelClass) { return CheckBox(html, id, name, value, text, labelClass, false, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>input的value值</param> /// <param>显示文本</param> /// <param>label标签的样式</param> /// <param>是否选中</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, object value, string text, string labelClass, bool isCheck) { return CheckBox(html, id, name, value, text, labelClass, isCheck, false, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>input的value值</param> /// <param>显示文本</param> /// <param>label标签的样式</param> /// <param>是否选中</param> /// <param>是否禁用</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, object value, string text, string labelClass, bool isCheck, bool isDisabled) { return CheckBox(html, id, name, value, text, labelClass, isCheck, isDisabled, null); } /// <summary> /// 返回表单CheckBox标签 /// </summary> /// <param>扩展方法实例</param> /// <param>id</param> /// <param>name属性</param> /// <param>input的value值</param> /// <param>显示文本</param> /// <param>label标签的样式</param> /// <param>是否选中</param> /// <param>是否禁用</param> /// <param>额外标签</param> /// <returns>返回CheckBox标签</returns> public static MvcHtmlString CheckBox(this BootstrapHelper html, string id, string name, object value, string text, string labelClass, bool isCheck, bool isDisabled, object oAttributes) { IDictionary<string, object> htmlAttributes = null; if (oAttributes != null) { htmlAttributes = BootstrapHelper.AnonymousObjectToHtmlAttributes(oAttributes); } else { htmlAttributes = new Dictionary<string, object>(); } return InputExtensions.CheckBox(html, InputType.CheckBox, id, name, value, text, labelClass, isCheck, isDisabled, htmlAttributes); } } }

博主将label和checkbox放到了一起,调用的时候传入对应的label文本即可,使用如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjssj.html