mvc4擴充方法

來源:互聯網
上載者:User

標籤:val   sum   製作   end   linq   html   exp   orm   returns   

製作擴充方法,方便網頁中使用,下面做了兩個例子

 

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>");            }        }    }}

 

mvc4擴充方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.