码迷,mamicode.com
首页 > Web开发 > 详细

MVC5 方法扩展

时间:2015-01-26 16:33:32      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:

public static MvcHtmlString DataDictionaryDropDownList(this HtmlHelper htmlHelper, string name, object htmlAttributes, List<SelectListItem> selectListItem)
        {
            return SelectExtensions.DropDownList(htmlHelper, name, selectListItem, htmlAttributes);
        }

        public static MvcHtmlString DataDictionaryDropDownList(this HtmlHelper htmlHelper, string name, string dataKeyName, object htmlAttributes, string checkedValue = null, IDataDictionaryAdapter adapter = null, params SelectListItem[] moreSelectItem)
        {
            //默认适配器
            if (adapter == null) adapter = new DataDictionaryAdapter();

            List<SelectListItem> selectListItem = adapter.GetSelectListItem(dataKeyName, checkedValue);

            //添加更多选择
            if (moreSelectItem != null) selectListItem.InsertRange(0, moreSelectItem);

            return DataDictionaryDropDownList(htmlHelper, name, htmlAttributes, selectListItem);
        }
        public static MvcHtmlString DataDictionaryDropDownList<T>(this HtmlHelper htmlHelper, string name, string dataKeyName, object htmlAttributes, string checkedValue = null, IDataDictionaryAdapter adapter = null, Action<T> beforeAction = null, params SelectListItem[] moreSelectItem)
        {
            //默认适配器
            if (adapter == null) adapter = new DataDictionaryAdapter();

            List<SelectListItem> selectListItem = adapter.GetSelectListItem<T>(dataKeyName, checkedValue, beforeAction);

            //添加更多选择
            if (moreSelectItem != null) selectListItem.InsertRange(0, moreSelectItem);

            return DataDictionaryDropDownList(htmlHelper, name, htmlAttributes, selectListItem);
        }

        public static MvcHtmlString ActionLink2(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes)
        {
            MvcHtmlString result = LinkExtensions.ActionLink(htmlHelper, linkText, actionName, routeValues, htmlAttributes);
            return HtmlDecode(result);
        }
        public static MvcHtmlString ActionLink2(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object htmlAttributes)
        {
            MvcHtmlString result = LinkExtensions.ActionLink(htmlHelper, linkText, actionName, controllerName, null, htmlAttributes);
            return HtmlDecode(result);
        }
        public static MvcHtmlString ActionLink2(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
        {
            MvcHtmlString result = LinkExtensions.ActionLink(htmlHelper, linkText, actionName, controllerName, routeValues, htmlAttributes);
            return HtmlDecode(result);
        }

        private static MvcHtmlString HtmlDecode(MvcHtmlString mvcHtmlString)
        {
            return new MvcHtmlString(HttpUtility.HtmlDecode(mvcHtmlString.ToHtmlString()));
        }

 

MVC5 方法扩展

标签:

原文地址:http://www.cnblogs.com/jasonlny/p/4250418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!