Html辅助方法(分页、下拉框)
2015-10-02 10:54
555 查看
引用命名空间:
Html分页方法
View Code
using System.Text; using System.Web.Mvc;
Html分页方法
public static HtmlString ExtDropDownList(this HtmlHelper htmlHelper, string name, string value, IEnumerable<SelectListItem> list, object attribute1, object attribute2) { TagBuilder select = new TagBuilder("select"); TagBuilder option = new TagBuilder("option"); if (!select.Attributes.ContainsKey("id") && name != null) select.GenerateId(name);//添加Id属性 if (!String.IsNullOrEmpty(name)) select.MergeAttribute("name", name);//添加那么属性 //添加节点 option.MergeAttribute("value", "0"); option.InnerHtml = "--请选择--"; select.InnerHtml += option; if (list != null) { foreach (var item in list) { if (!String.IsNullOrEmpty(value)) { if (item.Value == value) option.MergeAttribute("value", value); } else option.MergeAttribute("value", item.Value); option.InnerHtml = item.Text; select.InnerHtml += option; } } return ExtDropDownList(htmlHelper, select.ToString(), null, null, HtmlHelper.AnonymousObjectToHtmlAttributes(attribute1), HtmlHelper.AnonymousObjectToHtmlAttributes(attribute2)); }
View Code
相关文章推荐
- HTML学习记录<一>:<abbr>及<acronym>
- html,body{height:100%}
- c#写的一个html模板方案,不知道大家在asp.net上面使用的是不是也是这个原理
- 获取HTML标签当前在网页中的绝对位置
- html教程-1-概述扯淡
- html特殊字符
- html编程tips
- unittest测试驱动之HTMLTestRunner.py
- 正则表达式匹配HTML标签或标记
- html 不常用的标签
- HTML标签语义化
- W3school学习笔记之html
- 自定义HTML导航页
- HTML初步学习7
- <!DOCTYPE>是干嘛用的?— html文档类型
- HTML总结
- html实用小技巧
- SEO基础优化必学的8大html标签
- SEO基础优化必学的8大html标签
- html标签p和span