爱上MVC~为CheckBoxFor和RadioButtonFor加个扩展方法吧(希望MVC5把这方法收纳——呵呵)
说在前
我都是喜欢把问题复杂化,还有总是喜欢把问题简单化,偷懒化,这也需就是一个程序员的追求吧,呵呵。
我不太喜欢重复的东西,当你看到页面上有一个以上相同的代码时,那可以说,你的代码有重构的余地,应该考虑重构了,今天看了以前同事的博客,写了关于DropDownList的用法,如何将集合数据绑定到下拉列表框上,讲的不错,但最后在说checkbox和radiobutton时,我感觉有点重复了,我说的是代码重复了,还有就是代码复杂化了,就是说,我再使用集合来产生checkbox和radiobutton时,代码有些复杂了,这不是我们希望看到的,所以,我觉得有必要把它重构一下,为mvc加两个扩展方法吧,呵呵。
做在后
DropDownListFor的方法签名做的不错,很面向对象,很简洁,但不知不何,checkbox和radiobutton确没有这样的重载,呵呵
public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList);
public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, IDictionary<string, object> htmlAttributes);
public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, object htmlAttributes);
public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, string optionLabel);
public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, string optionLabel, IDictionary<string, object> htmlAttributes);
public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, string optionLabel, object htmlAttributes);
对于checkbox和radiobutton它们只有简单的几个重载,没有对集合的支持,所以,我的这次代码扩展,主要是针对集合来说的,看方法签名:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAABzCAIAAAD/iSpLAAAgAElEQVR4nO2dfZhrVX3vU2yt4sUHCvUNX4pKi1Dk+AKW6+1VKlhKLVq0Vu9ztMoFvRyolatAKaI8QqkeC4h9KuAIVMFCGbWsZCZnMpnMJHPyNklOkpkkZ5JMkjPJ5GX25KfPOfUOf/jPuX+sl73Wfkl2Mplh5vD7PjwkZ2fttVcyc/I5v9/67d/XdRyFQqFQqN2qk+V/pP/96le/2tzc/LXv0pNcrhd7bSgUCoVC9dGJEycQYCgUCoXae+oDsM38937tu5T+t5n/Hh7BI3gEj+ARPLIbjvQH2PHjxwGFQqFQqN2kX/sudRSBvdjrRKFQKBRKkSOA/dp3ad+JkuMHx/wrVn/YupLjBw/aTbjiHzs4nhzZpVAoFAq1RzQygAGs+MfG/CsUKTJt+HGA5PiYfyU5rqKIDV/xjx1UNOZfoeQ6ePDgwfEkHSjEmSVGGM7c2nX5zONJ+YkseTZ1gGlC48QoFAqF6qnV1dWclVZXV+VhjvbATABLjh8cT0qEsPzSlr6w6XgDbMaTMn/GxsYOjo2Pj5nP5nwQYNSB0QNfW7qu9LLfL58tJmcAs5jayG/gHxACDIVCoRwpl8s5OU4JNeAeGCMXxYN0wBT10Cf0q398fIx956vf5MnxgzwSMuDJwMWxMcOIFf/YuF8hg8yJLVyXP+d4ooeVkYJulqyyFAIMhUKhHMkhwAavQjQEHSJr2OMLe8U/NuZPmsaIBN3BgwcZifRwh7OETz2etESN+coSJ4a+rhyBJflllShKRGDWwZYU0iHAUCgUajA5BNgwVYimAKw3wOQyi+Q4DXoMJ46NjYkz1B0lK1w6BNgWrqtHYFKMZgDYQSm6M3w6pkAR4YVCoVDORUEVVgXDAUzeA7PY9ZGkpxDlQxwSDCkr/rHxJP8fzwyaAhe+VTU2Nma7B2Zez0Fj/nHo6wqAyeUeUgqRv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age2Q1HegHsVygUCoVC7VbZAuzEiRP/D4VCoVCo3Spx+5YFwDZRKBQKhdqtsgTY/wdI7zGE0YQWZgAAAABJRU5ErkJggg==" alt="" />
下面看一下原代码,它直接写在了System.Web.Mvc命名空间下,这更说明我是对微软MVC的一个扩展,希望MVC5出来时,可以把这些都集成进去,呵呵
#region 单选框和复选框的扩展
/// <summary>
/// 复选框,selValue为选中项
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="name"></param>
/// <param name="selectList"></param>
/// <param name="selValue"></param>
/// <returns></returns>
public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList, IEnumerable<string> selValue)
{
return CheckBoxAndRadioFor<object, string>(name, selectList, false, selValue);
}
public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList, string selValue)
{
return CheckBox(htmlHelper, name, selectList, new List<string> { selValue }); }
/// <summary>
/// 复选框
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="name"></param>
/// <param name="selectList"></param>
/// <returns></returns>
public static MvcHtmlString CheckBoxFor(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList)
{
return CheckBox(htmlHelper, name, selectList, new List<string>());
}
/// <summary>
/// 根据列表输出checkbox
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="htmlHelper"></param>
/// <param name="expression"></param>
/// <param name="selectList"></param>
/// <returns></returns>
public static MvcHtmlString CheckBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList)
{
return CheckBoxFor(htmlHelper, expression, selectList, null);
} /// <summary>
/// 根据列表输出checkbox,selValue为默认选中的项
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="htmlHelper"></param>
/// <param name="expression"></param>
/// <param name="selectList"></param>
/// <param name="selValue"></param>
/// <returns></returns>
public static MvcHtmlString CheckBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, string selValue)
{
string name = ExpressionHelper.GetExpressionText(expression);
return CheckBoxAndRadioFor<TModel, TProperty>(name, selectList, false, new List<string> { selValue });
}
/// <summary>
/// 输出单选框和复选框
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="expression"></param>
/// <param name="selectList"></param>
/// <param name="isRadio"></param>
/// <param name="selValue"></param>
/// <returns></returns>
static MvcHtmlString CheckBoxAndRadioFor<TModel, TProperty>(
string name,
IEnumerable<SelectListItem> selectList,
bool isRadio,
IEnumerable<string> selValue)
{
StringBuilder str = new StringBuilder();
int c = ;
string check, activeClass;
string type = isRadio ? "Radio" : "checkbox"; foreach (var item in selectList)
{
c++;
if (selValue != null && selValue.Contains(item.Value))
{
check = "checked='checked'";
activeClass = "style=color:red";
}
else
{
check = string.Empty;
activeClass = string.Empty;
}
str.AppendFormat("<span><input type='{3}' value='{0}' name={1} id={1}{2} " + check + "/>", item.Value, name, c, type);
str.AppendFormat("<label for='{0}{1}' {3}>{2}</lable></span>", name, c, item.Text, activeClass); }
return MvcHtmlString.Create(str.ToString());
} public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList, IEnumerable<string> selValue)
{
return CheckBoxAndRadioFor<object, string>(name, selectList, true, selValue);
}
/// <summary>
/// 单选按钮组,seletList为选中项
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="name"></param>
/// <param name="selectList"></param>
/// <param name="selValue"></param>
/// <returns></returns>
public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList, string selValue)
{
return RadioButton(htmlHelper, name, selectList, new List<string> { selValue });
}
/// <summary>
/// 单选按钮组
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="name"></param>
/// <param name="selectList"></param>
/// <returns></returns>
public static MvcHtmlString RadioButton(this HtmlHelper htmlHelper, string name, IEnumerable<SelectListItem> selectList)
{
return RadioButton(htmlHelper, name, selectList, new List<string>());
}
/// <summary>
/// 根据列表输出radiobutton
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="htmlHelper"></param>
/// <param name="expression"></param>
/// <param name="selectList"></param>
/// <returns></returns>
public static MvcHtmlString RadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList)
{
return RadioButtonFor(htmlHelper, expression, selectList, new List<string>());
}
public static MvcHtmlString RadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, IEnumerable<string> selValue)
{
string name = ExpressionHelper.GetExpressionText(expression);
return CheckBoxAndRadioFor<TModel, TProperty>(name, selectList, true, selValue);
}
/// <summary>
/// 根据列表输出radiobutton,selValue为默认选中的项
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <typeparam name="TProperty"></typeparam>
/// <param name="htmlHelper"></param>
/// <param name="expression"></param>
/// <param name="selectList"></param>
/// <param name="selValue"></param>
/// <returns></returns>
public static MvcHtmlString RadioButtonFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, string selValue)
{
return RadioButtonFor(htmlHelper, expression, selectList, new List<string> { selValue });
}
#endregion
爱上MVC~为CheckBoxFor和RadioButtonFor加个扩展方法吧(希望MVC5把这方法收纳——呵呵)的更多相关文章
- 在MVC应用程序中动态加载PartialView
原文:在MVC应用程序中动态加载PartialView 有时候,我们不太想把PartialView直接Render在Html上,而是使用jQuery来动态加载,或是某一个事件来加载.为了演示与做好这个 ...
- Spring MVC 项目搭建 -4- spring security-添加自定义登录页面
Spring MVC 项目搭建 -4- spring security-添加自定义登录页面 修改配置文件 <!--spring-sample-security.xml--> <!-- ...
- 【Spring MVC】Properties文件的加载
[Spring MVC]Properties文件的加载 转载:https://www.cnblogs.com/yangchongxing/p/10726885.html 参考:https://java ...
- 爱上MVC~图表的使用Chart
回到目录 图表在一个系统中是必须的,MVC架构把它当然是一个扩展集成了进来,通过简单的几句话就可以生成一个风格多样的图表,这给报表的开发带来了很大的方便,大叔的项目中也做了一个测试,把主要的代码贴出来 ...
- Spring MVC 后端获取前端提交的json格式字符串并直接转换成control方法对应的参数对象
场景: 在web应用开发中,spring mvc凭借出现的性能和良好的可扩展性,导致使用日渐增多,成为事实标准,在日常的开发过程中,有一个很常见的场景:即前端通过ajax提交方式,提交参数为一个jso ...
- 百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法
百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法 金刚 前端 ueditor 初始化 因项目中使用了百度编辑器——ueditor.整体来说性能还不错. 发现问题 我在做一个编辑页面 ...
- Asp.net MVC的Model Binder工作流程以及扩展方法(2) - Binder Attribute
上篇文章中分析了Custom Binder的弊端: 由于Custom Binder是和具体的类型相关,比如指定类型A由我们的Custom Binder解析,那么导致系统运行中的所有Action的访问参 ...
- .Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) 通过MVC控制器导出导入Excel文件(可用于java SSH架构)
.Net MVC 导入导出Excel总结(三种导出Excel方法,一种导入Excel方法) [原文地址] 通过MVC控制器导出导入Excel文件(可用于java SSH架构) public cl ...
- ASP.NET MVC 3 loginUrl自动变成Account/Login,并且发生404错误的解决方法
http://www.cnblogs.com/think8848/archive/2011/07/08/2100814.html ASP.NET MVC 3 loginUrl自动变成Account/L ...
随机推荐
- ros学习笔记 - 深度传感器转换成激光数据(hector_slam)
前提条件:1,确保读者已经安装了kinect或者其他深度摄像头的驱动,如果未安装,可以直接在网盘下载:http://pan.baidu.com/s/1hqHB10w 提取密码:wrmn 利用深度相机仿 ...
- Field 'id' doesn't have a default value(jdbc连接错误)
JDBC 连接错误: 编写数据库连接增添数据时,出现以下错误: error : java.sql.SQLException: Field 'id' doesn't have a default val ...
- 【Thinking in Java】Java Callable的使用
Callable<>和Runable类似,都是用于Java的并发执行. 唯一的区别是,Runable的run方法的返回是void,而Callable的call方法是有返回值的. call方 ...
- iOS 字符串转son json转字符串
+ (NSString*)dictionaryToJson:(NSDictionary *)dic { NSError *parseError = nil; NSData *jsonDa ...
- Mini projects #3 ---- Stopwatch: The Game
课程全名:An Introduction to Interactive Programming in Python,来自 Rice University 授课教授:Joe Warren, Scott ...
- .net之微信企业号开发(三) 回调模式的接口开发
一.前言 微信企业号应用中,有两种模式,一种是普通模式,这种模式只能进行简单网页链接,以及发送固定的消息.为了可以让企业号的用户更好的与应用交互,微信提供了回调模式,这种回调模式的可以将用户发送给微信 ...
- Android 多个include标签的监听事件处理
include标签的作用是为了xml文件代码的模块化,详细不再多提.主要是说说include标签的监听. 网上也有很多例子,不过大多是只写了一个include标签的监听,如果需要实现多个include ...
- webdriver 获取alert 提示no alert is active
http://hi.baidu.com/janice515/item/bce536bb136e8441bb0e120f 摘上面: 一般正常情况下会报错,如 no alert is active 目 ...
- Eclipse断点调试
转自:http://blog.csdn.net/maritimesun/article/details/7815903 作为开发人员,掌握开发环境下的调试技巧十分有必要.去年就想把关于Eclipse断 ...
- 学习Word2vec
有感于最近接触到的一些关于深度学习的知识,遂打算找个东西来加深理解.首选的就是以前有过接触,且火爆程度非同一般的word2vec.严格来说,word2vec的三层模型还不能算是完整意义上的深度学习,本 ...