zoukankan      html  css  js  c++  java
  • mvc4扩展方法

    制作扩展方法,方便网页中使用,下面做了两个例子

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Text;
    using System.Web;
    
    namespace System.Web.Mvc
    {
        public static class CheckBoxListHelper
        {
            public static MvcHtmlString CheckBoxList(this HtmlHelper helper, string[] showStr,string attrName, bool isHorizon = true)
            {
                if (showStr == null)
                    return null;
                if (attrName == null)
                {
                    attrName = "temp";
                }
                StringBuilder sb = new StringBuilder();
                int i=0;
                foreach (var item in showStr)
                {
                    i++;
                    sb.Append("<label class='checkbox-inline'>");
                    sb.Append(string.Format("<input type='checkbox' id='{0}' name='{0}' value='{1}'>{1}</input>", attrName + i, item));
                    sb.Append("</label>");
                }
                return new MvcHtmlString(sb.ToString());
            }
            /// <summary>
            /// 截取字符长度
            /// </summary>
            /// <param name="helper"></param>
            /// <param name="showStr"></param>
            /// <param name="attrName"></param>
            /// <param name="isHorizon"></param>
            /// <returns></returns>
            public static MvcHtmlString GetStringSub(this HtmlHelper helper, string s, int len)
            {
                if (string.IsNullOrEmpty(s))
                    return new MvcHtmlString("");
                if (s.Length <= len)
                    return new MvcHtmlString(s.ToString());
                else
                {
                    return new MvcHtmlString("<span title='" + s + "'>" + s.Substring(0, len) + ".</span>");
                }
            }
        }
    }
  • 相关阅读:
    Python·Jupyter Notebook
    CNN(卷积神经网络)、RNN(循环神经网络)、DNN(深度神经网络)概念区分理解
    tensorflow学习
    语料库
    资源 | 数十种TensorFlow实现案例汇集:代码+笔记
    Tensorlayer
    利用 TFLearn 快速搭建经典深度学习模型
    十分钟搞定pandas
    利用python进行数据分析之pandas入门
    Pandas
  • 原文地址:https://www.cnblogs.com/lunawzh/p/6107639.html
Copyright © 2011-2022 走看看