您的位置:首页 > Web前端 > HTML

Html辅助方法(分页、下拉框)

2015-10-02 10:54 555 查看
引用命名空间:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: