cs-HtmlHelpers
| ylbtech-Unitity: cs-HtmlHelpers |
PagingHelpers.cs SelectInputHelpers.cs TreeHelpers.cs
| 1.A,效果图返回顶部 |
| 1.B,源代码返回顶部 |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using Core.Repository; namespace Core.HtmlHelpers
{
public static class PagingHelpers
{
public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl, string fnData = "")
{
StringBuilder result = new StringBuilder();
for (int i = ; i <= pagingInfo.TotalPages; i++)
{
result.AppendLine("<a href='#' ");//
if (i == pagingInfo.CurrentPage)
result.Append(" class='selected' ");
result.Append( " onclick=\"pageing(this," + i + ",'" + fnData + "')\">" + i + "</a>"); ////TagBuilder tag = new TagBuilder("a"); //创建<a>标签
////tag.MergeAttribute("href", "#");//pageUrl(i));
////tag.MergeAttribute("onclick", "pageing(this," + i + ",'" + fnData + "');"); ////tag.InnerHtml = i.ToString();
//if (i == pagingInfo.CurrentPage)
// tag.AddCssClass("selected");
//result.Append(tag.ToString() + " ");
}
return MvcHtmlString.Create("共" + pagingInfo.TotalItems + "条,当前第" + pagingInfo.CurrentPage + "页,共" + pagingInfo.TotalPages + "页 " + result.ToString());
}
} }
1.B.2,SelectInputHelpers.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using System.Collections;
using System.Reflection; namespace Core.HtmlHelpers
{
public static class SelectInputHelpers
{
public static MvcHtmlString SelectInput(this HtmlHelper html, string name, SelectList Options,string optionLabel=null, object htmlAttributes=null)
{
StringBuilder result = new StringBuilder("<select id=\"" + name+"\" name=\""+name+"\"");
if (htmlAttributes != null)
{
PropertyInfo[] pis = htmlAttributes.GetType().GetProperties(); foreach (PropertyInfo item in pis)
{
result.Append(" " + item.Name + "=\"" + item.GetValue(htmlAttributes, null) + "\"");
}
}
result.Append(">"); if(optionLabel!=null)
result.AppendLine("<option value=\"\">" + optionLabel + "</option>"); foreach (var item in Options.Items)
{
var Value=item.GetType().GetProperty(Options.DataValueField).GetValue(item, null);
var Text=item.GetType().GetProperty(Options.DataTextField).GetValue(item, null); if (Options.SelectedValue != null&&Value.ToString() == Options.SelectedValue.ToString())
result.AppendLine("<option value=\"" + Value + "\" selected>" + Text + "</option>");
else
result.AppendLine("<option value=\"" + Value + "\">" + Text + "</option>");
}
result.AppendLine("</select>");
return MvcHtmlString.Create(result.ToString());//"共" + pagingInfo.TotalItems + "条,当前第" + pagingInfo.CurrentPage + "页,共" + pagingInfo.TotalPages + "页 " + result.ToString());
}
} }
1.B.3,TreeHelpers.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using System.Collections.Specialized;
using Core.WebHelper; namespace Core.HtmlHelpers
{
public static class TreeHelpers
{
public static MvcHtmlString Tree(this HtmlHelper html,Tree tree )
{
IEnumerable<TreeNode> treeModels = tree.TreeNodes;
StringBuilder sb=new StringBuilder();
var root = treeModels.Where(p => p.ParentTreeNodeID == null || p.ParentTreeNodeID == "" || p.ParentTreeNodeID == "").ToArray();
var count = root.Count();
if (count > )
{
if(tree.ShowLine)
sb.AppendLine("<ul class='ulDashed'>");
else
sb.AppendLine("<ul >");
for (int i = ; i < count; i++)// var item in root)
{
//HtmlString += "<li>";// +item.Name;
if (i == count - )
{
if (tree.ShowLine)
sb.AppendLine("<li class='last liDashed'>");
else
sb.AppendLine("<li class='last'>");
}
else
{
if (tree.ShowLine)
sb.AppendLine("<li class='liDashed'>");
else
sb.AppendLine("<li>");
}
List<TreeNode> Sublist = treeModels.Where(p => p.ParentTreeNodeID == root[i].TreeNodeID).ToList();//.ModularFuns.ToList();
int SubCount = Sublist.Count();
#region 显示开始图标 if (SubCount > )//非叶节点
{
if (tree.ExpentDepth > )
sb.AppendLine("<span class='minus' ></span>");//+
else
sb.AppendLine("<span class='plus'></span>");//+
//HtmlString += "<img src='/images/Tree/minus.gif'/>";//展开图标 }
//else
// sb.AppendLine("<span class='minus'></span>");
//else//叶节点
//{
// if (i == count - 1)
// HtmlString += "<span class='bindPic checkBoxPic'></span>";// "<img src='/images/Tree/line2.gif'/>";
// else
// HtmlString += "class='last'";// "<img src='/images/Tree/line3.gif'/>";
//}
#endregion #region 复选框
//if(NVC["bCheck"]=="1")
if (tree.ShowCheckBox == ShowCheckBoxs.Root || tree.ShowCheckBox == ShowCheckBoxs.All)
sb.AppendLine("<span class='bindPic checkBoxPic'></span>"); #endregion #region 显示类型标记图标 if (SubCount > )//非叶节点
{
if (tree.ExpentDepth > )
sb.AppendLine("<span class='bindPic iconDirOpen'></span>");//+
else
sb.AppendLine("<span class='bindPic iconDirClosed'></span>");
//sb.AppendLine("<span class='bindPic iconDirOpen'></span>");// "<img src='/images/Tree/folderopen.gif'/>";//展开图标
}
else
{
sb.AppendLine("<span class='bindPic iconFile'></span>");
} #endregion #region a
if (root[i].NodeDispType == NodeDispType.Alink)
{
//TagBuilder tag = new TagBuilder("a"); //创建<a>标签
//tag.MergeAttribute("href", "#");//pageUrl(i));
//tag.MergeAttribute("pathValue", "/" + root[i].Text);
////tag.MergeAttribute("onclick", "nav('" + root[i].Url + "')");//," + i + ");");
//tag.InnerHtml = root[i].Text;
sb.AppendLine("<a href='#' " + root[i].htmlAttr + ">"+root[i].Text+"</a>");
//sb.AppendLine(tag.ToString());
}
else
{
//sb.AppendLine("<span>"+root[i].Text +"</span>");
sb.AppendLine("<span " + root[i].htmlAttr + " pathValue='/" + root[i].Text + "'>" + root[i].Text + "</span>");
}
#endregion sb.AppendLine(BindTree(root[i], tree,,"/"+root[i].Text));
sb.AppendLine("</li>");
}
sb.AppendLine("</ul>");
}
MvcHtmlString mstr = new MvcHtmlString(sb.ToString()); return mstr;
}
private static string BindTree(TreeNode treeModel, Tree tree,int lev,string PathValue)
{
lev++;
IEnumerable<TreeNode> treeModels = tree.TreeNodes;
StringBuilder sb = new StringBuilder();
if (treeModel != null)
{
List<TreeNode> root = treeModels.Where(p => p.ParentTreeNodeID == treeModel.TreeNodeID).ToList();//.ModularFuns.ToList();
int count = root.Count;
if (count > )
{
if (tree.ExpentDepth >= lev)
{
if (tree.ShowLine)
sb.AppendLine("<ul class='ulDashed'>");
else
sb.AppendLine("<ul >");
}
else
{
if (tree.ShowLine)
sb.AppendLine("<ul class=hidden ulDashed'>");
else
sb.AppendLine("<ul class='hidden'>");
}
for (int i = ; i < count; i++)// var item in root)
{
if (i == count - )
{
if (tree.ShowLine)
sb.AppendLine("<li class='last liDashed'>");
else
sb.AppendLine("<li class='last'>");
//sb.AppendLine("<li class='last'>");
}
else
{
// sb.AppendLine("<li>");
if (tree.ShowLine)
sb.AppendLine("<li class='liDashed'>");
else
sb.AppendLine("<li>");
}
List<TreeNode> Sublist = treeModels.Where(p => p.ParentTreeNodeID == root[i].TreeNodeID).ToList();//.ModularFuns.ToList();
int SubCount = Sublist.Count(); #region 显示开始图标 if (SubCount > )//非叶节点
{
//HtmlString += "<img src='/images/Tree/minus.gif'/>";//展开图标
//sb.AppendLine("<span class='plus'></span>");
if (tree.ExpentDepth > lev)
sb.AppendLine("<span class='minus'></span>");//+
else
sb.AppendLine("<span class='plus'></span>");//+
} #endregion #region 复选框
if ((SubCount>&&tree.ShowCheckBox == ShowCheckBoxs.Parent)||tree.ShowCheckBox == ShowCheckBoxs.All)
sb.AppendLine("<span class='bindPic checkBoxPic' Value='"+root[i].Value+"' ></span>");
else if ((SubCount == && tree.ShowCheckBox == ShowCheckBoxs.Leaf) || tree.ShowCheckBox == ShowCheckBoxs.All)
sb.AppendLine("<span class='bindPic checkBoxPic' Value='" + root[i].Value + "'></span>");
#endregion #region 显示类型标记图标 if (SubCount > )//非叶节点
{
if (tree.ExpentDepth > lev)
sb.AppendLine("<span class='bindPic iconDirOpen'></span>");//+
else
sb.AppendLine("<span class='bindPic iconDirClosed'></span>");
}
else
sb.AppendLine("<span class='bindPic iconFile'></span>");//文件图标
#endregion #region a
//if (root[i].Url.Trim().Length > 0)
//{
// //TagBuilder tag = new TagBuilder("a"); //创建<a>标签
// //tag.MergeAttribute("href", "#");//pageUrl(i));
// //tag.MergeAttribute("pathValue", PathValue + "/" + root[i].Text);
// //tag.MergeAttribute("onclick", "nav('" + root[i].Url + "')");//," + i + ");");
// //tag.InnerHtml = root[i].Text;
// sb.AppendLine(tag.ToString());
//}
//else
//{
// sb.AppendLine("<span "+root[i].htmlAttr+" pathValue='" + PathValue + "/" + root[i].Text + "'>" + root[i].Text + "</span>");
//}
if (root[i].NodeDispType == NodeDispType.Alink)
{
//TagBuilder tag = new TagBuilder("a"); //创建<a>标签
//tag.MergeAttribute("href", "#");//pageUrl(i));
//tag.MergeAttribute("pathValue", "/" + root[i].Text);
////tag.MergeAttribute("onclick", "nav('" + root[i].Url + "')");//," + i + ");");
//tag.InnerHtml = root[i].Text;
sb.AppendLine("<a href='#' " + root[i].htmlAttr + ">" + root[i].Text + "</a>");
//sb.AppendLine(tag.ToString());
}
else
{
//sb.AppendLine("<span>"+root[i].Text +"</span>");
sb.AppendLine("<span " + root[i].htmlAttr + " pathValue='/" + root[i].Text + "'>" + root[i].Text + "</span>");
}
#endregion sb.Append(BindTree(root[i], tree, lev, PathValue+"/"+root[i].Text));
sb.AppendLine("</li>"); //foreach (var item in list)
//{
// sb.Append("<li>"); // TagBuilder tag = new TagBuilder("a"); //创建<a>标签
// tag.MergeAttribute("href", "#");//pageUrl(i));
// tag.MergeAttribute("onclick", "nav('/" + item.ControllName + "/" + item.ActionName + "')");//," + i + ");");
// tag.InnerHtml = item.Name; // sb.Append(tag.ToString());
// sb.Append("</li>");
// sb.Append(BindTree(item, treeModels));
//}
}
sb.Append("</ul>");
}
}
//MvcHtmlString mstr = new MvcHtmlString(sb.ToString());
return sb.ToString();
}
//public static MvcHtmlString Tree(this HtmlHelper html, IEnumerable<ModularFun> treeModels)
//{
// string HtmlString ="";
// var root = treeModels.Where(p => p.ParentModularFunID == null).ToArray();
// var count = root.Count();
// if (count > 0)
// {
// HtmlString = "<ul>";
// for (int i = 0; i < count; i++)// var item in root)
// {
// //HtmlString += "<li>";// +item.Name;
// if (i == count - 1)
// {
// HtmlString += "<li class='last'>";
// }
// else
// HtmlString += "<li>";
// List<ModularFun> Sublist = treeModels.Where(p => p.ParentModularFunID == root[i].ModularFunID).ToList();//.ModularFuns.ToList();
// int SubCount = Sublist.Count();
// #region 显示开始图标 // if (SubCount > 0)//非叶节点
// {
// //HtmlString += "<img src='/images/Tree/minus.gif'/>";//展开图标
// HtmlString += "<span class='minus'></span>";
// }
// //else//叶节点
// //{
// // if (i == count - 1)
// // HtmlString += "<span class='bindPic checkBoxPic'></span>";// "<img src='/images/Tree/line2.gif'/>";
// // else
// // HtmlString += "class='last'";// "<img src='/images/Tree/line3.gif'/>";
// //}
// #endregion // #region 复选框
// //if(NVC["bCheck"]=="1")
// HtmlString += "<span class='bindPic checkBoxPic'></span>"; // #endregion // #region 显示类型标记图标 // if (SubCount > 0)//非叶节点
// {
// HtmlString += "<span class='bindPic iconDir'></span>";// "<img src='/images/Tree/folderopen.gif'/>";//展开图标
// }
// else
// {
// HtmlString += "<span class='bindPic iconFile'></span>";
// } // #endregion // #region a // TagBuilder tag = new TagBuilder("a"); //创建<a>标签
// tag.MergeAttribute("href", "#");//pageUrl(i));
// tag.MergeAttribute("onclick", "nav('/" + root[i].ControllName + "/" + root[i].ActionName + "')");//," + i + ");");
// tag.InnerHtml = root[i].Name;
// HtmlString += tag.ToString(); // #endregion // HtmlString += BindTree(root[i], treeModels);
// HtmlString += "</li>";
// }
// HtmlString += "</ul>";
// }
// MvcHtmlString mstr = new MvcHtmlString(HtmlString.ToString()); // return mstr;
//}
//private static MvcHtmlString BindTree(ModularFun treeModel, IEnumerable<ModularFun> treeModels)
//{
// StringBuilder sb = new StringBuilder();
// if (treeModel != null)
// {
// List<ModularFun> root = treeModels.Where(p => p.ParentModularFunID == treeModel.ModularFunID).ToList();//.ModularFuns.ToList();
// int count = root.Count;
// if (count > 0)
// {
// sb.AppendLine("<ul>");
// for (int i = 0; i < count; i++)// var item in root)
// {
// if (i == count - 1)
// {
// sb.AppendLine("<li class='last'>");
// }
// else
// sb.AppendLine("<li>");
// List<ModularFun> Sublist = treeModels.Where(p => p.ParentModularFunID == root[i].ModularFunID).ToList();//.ModularFuns.ToList();
// int SubCount = Sublist.Count(); // #region 显示开始图标 // if (SubCount > 0)//非叶节点
// {
// sb.AppendLine("<span class='minus'></span>");//展开图标
// }
// //else//叶节点
// //{
// // if (i == count - 1)
// // sb.AppendLine("<img src='/images/Tree/lastli.gif'/>");
// // else
// // sb.AppendLine("<img src='/images/Tree/line3.gif'/>");
// //}
// #endregion // #region 复选框 // sb.AppendLine("<span class='bindPic checkBoxPic'></span>"); // #endregion // #region 显示类型标记图标 // if (SubCount > 0)//非叶节点
// {
// sb.AppendLine("<span class='bindPic iconDir'></span>");//展开图标
// }
// else
// sb.AppendLine("<span class='bindPic iconFile'></span>");//展开图标
// #endregion // #region a // TagBuilder tag = new TagBuilder("a"); //创建<a>标签
// tag.MergeAttribute("href", "#");//pageUrl(i));
// tag.MergeAttribute("onclick", "nav('/" + root[i].ControllName + "/" + root[i].ActionName + "')");//," + i + ");");
// tag.InnerHtml = root[i].Name;
// sb.AppendLine(tag.ToString()); // #endregion // sb.Append(BindTree(root[i], treeModels));
// sb.AppendLine("</li>"); // //foreach (var item in list)
// //{
// // sb.Append("<li>"); // // TagBuilder tag = new TagBuilder("a"); //创建<a>标签
// // tag.MergeAttribute("href", "#");//pageUrl(i));
// // tag.MergeAttribute("onclick", "nav('/" + item.ControllName + "/" + item.ActionName + "')");//," + i + ");");
// // tag.InnerHtml = item.Name; // // sb.Append(tag.ToString());
// // sb.Append("</li>");
// // sb.Append(BindTree(item, treeModels));
// //}
// }
// sb.Append("</ul>");
// }
// }
// MvcHtmlString mstr = new MvcHtmlString(sb.ToString());
// return mstr;
//}
}
}
1.B.4,
| 1.C,下载地址返回顶部 |
![]() |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
cs-HtmlHelpers的更多相关文章
- [C#] 剖析 AssemblyInfo.cs - 了解常用的特性 Attribute
剖析 AssemblyInfo.cs - 了解常用的特性 Attribute [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5944391.html 序 ...
- Atitit 软件架构方法的进化与演进cs bs soa roa msa attilax总结
Atitit 软件架构方法的进化与演进cs bs soa roa msa attilax总结 1.1. 软件体系架构是沿着单机到 CS 架构,再到 BS 的三层架构甚至多层架构逐步发展过来的,关于 ...
- 从java文件和CS文件里查询方法使用次数工具
前几天,领导让我找一下老系统(Java)里getRemoteUser方法都哪个文件用了,package是什么,方法被调用了多少次,当时因为着急,所以,直接人工找的,但是以后要是再出现,人工找就太讨厌了 ...
- 关于 WP 开发中.xaml 与.xaml.cs 的关系
今天我们先来看一下在WP8.1开发中最长见到的几个文件之间的关系.比较论证,在看这个问题之前我们简单看看.NET平台其他两个不同的框架: Windows Forms 先看看Window Forms中的 ...
- .net 用户控件ascx.cs注册js脚本代码无效果
在.net web项目中碰到一个比较奇怪的问题,网上没找到解决方案,先自己mark一下 问题描述: 添加一个用户控件ascx,在后端.cs添加js注册脚本,执行后没有弹出框 注册脚本为: this.P ...
- DateHelper.cs日期时间操作辅助类C#
//==================================================================== //** Copyright © classbao.com ...
- 仅用aspx文件实现Ajax调用后台cs程序。(实例)
仅用aspx文件实现Ajax调用后台cs无刷新程序.(实例) 两个文件:aaa.aspx 和aaa.aspx.cs 一.aaa.aspx <script type="text/java ...
- Etw EventSourceProvider_EventsProducer.cs OopConsoleTraceEventListenerMonitor_TraceControllerEventsConsumer.cs
// EventSourceProvider_EventsProducer.cs /* /r:"D:\Microshaoft.Nuget.Packages\Microsoft.Diagnos ...
- WPF根据Oracle数据库的表,生成CS文件小工具
开发小工具的原因: 1.我们公司的开发是客户端用C#,服务端用Java,前后台在通讯交互的时候,会用到Oracle数据库的字段,因为服务器端有公司总经理开发的一个根据Oracle数据库的表生成的cla ...
- 用CS的思维可以指导BS的项目吗?
最近项目上线,越来越觉的让人不爽.1.在录数据的界面领导要求用Enter键一路打下来,用户不用操作鼠标数据就可以录完. 2.CS的项目中用快捷键的确很方便,但是大家在BS的项目中也用快捷键吗? 反正我 ...
随机推荐
- 【洛谷 P3629】 [APIO2010]巡逻 (树的直径)
题目链接 容易发现,当加一条边时,树上会形成一个环,这个环上的每个点都是只要走一次的,也就是说我们的答案减少了这个环上点的个数,要使答案最小,即要使环上的点最多,求出直径\(L\),则答案为\(2(n ...
- 【洛谷 P4342】[IOI1998]Polygon(DP)
题目链接 题意不再赘述. 这题和合并石子很类似,但是多了个乘法,而乘法是不满足"大大得大"的,因为两个非常小的负数乘起来也会很大,一个负数乘一个很大的整数会很小,所以我们需要添加一 ...
- memcached启动脚本(class练习)
说明:使用类的方式编写程序启动脚本(memcached) import time import os from subprocess import Popen,PIPE class Process(o ...
- Linux上使用程序相对路径访问文件【转】
转自:http://blog.csdn.net/yinxusen/article/details/7444249 今天一个朋友问我这个问题,说为什么在Windows上跑得很好的应用程序,移植到Linu ...
- Codeforces 270E Flawed Flow 网络流问题
题意:给出一些边,给出边的容量.让你为所有边确定一个方向使得流量最大. 题目不用求最大流, 而是求每条边的流向,这题是考察网络流的基本规律. 若某图有最大,则有与源点相连的边必然都是流出的,与汇点相连 ...
- App云测试平台免费功能汇总
Wetest http://wetest.qq.com 阿里云测 https://mqc.aliyun.com/ Testbird https://www.testbird.com/ 百度 htt ...
- vbs登陆网站
Option Explicit Dim objIE Set objIE = CreateObject("InternetExplorer.Application") objIE.V ...
- node中通过orm2链接mysql的一个坑
代码是orm上的例子,出现如下错误: ORMError: Connection protocol not supported - have you installed the database dri ...
- hdu4240 求一条流量最大的路/(此题网上百分之90以上算法是错误的)
题意:求最大流/一条流量最大的路的流量.(此题HDU上数据水,下面俩种错误的都能过....) 思路1;每次增广的时候更新流量,保存最大的那条. 错误性:每次更新,有可能最大的那条流量是前几次已经增广 ...
- mySQL的存储过程详解
mysql存储过程详解 1. 存储过程简介 我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成特定功能的S ...
