The main reborn ASP.NET MVC4.0: using CheckBoxListHelper and RadioBoxListHelper

The new Helpers folder in the project, to create the CheckBoxListHelper and RadioBoxListHelper classes.

CheckBoxListHelper code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace SHH.Helpers
{
    public static class CheckBoxListHelper
    {
        public static MvcHtmlString CheckBoxList(this HtmlHelper helper, string name, bool isHorizon = true)
        {
            return CheckBoxList(helper, name, helper.ViewData[name] as IEnumerable<SelectListItem>, new { }, isHorizon);
        }

        public static MvcHtmlString CheckBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> selectList, bool isHorizon = true)
        {
            return CheckBoxList(helper, name, selectList, new { }, isHorizon);
        }

        public static MvcHtmlString CheckBoxListFor<TModel, TProperty>(this HtmlHelper helper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItem> selectList, bool isHorizon = true)
        {
            string[] propertys = expression.ToString().Split(".".ToCharArray());
            string id = string.Join("_", propertys, 1, propertys.Length - 1);
            string name = string.Join(".", propertys, 1, propertys.Length - 1);

            return CheckBoxList(helper, id, name, selectList, new { }, isHorizon);
        }

        public static MvcHtmlString CheckBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> selectList, object htmlAttributes, bool isHorizon = true)
        {
            return CheckBoxList(helper, name, name, selectList, htmlAttributes, isHorizon);
        }

        public static MvcHtmlString CheckBoxList(this HtmlHelper helper, string id, string name, IEnumerable<SelectListItem> selectList, object htmlAttributes, bool isHorizon = true)
        {
            IDictionary<string, object> HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            HashSet<string> set = new HashSet<string>();
            List<SelectListItem> list = new List<SelectListItem>();
            string selectedValues = (selectList as SelectList).SelectedValue == null ? string.Empty : Convert.ToString((selectList as SelectList).SelectedValue);
            if (!string.IsNullOrEmpty(selectedValues))
            {
                if (selectedValues.Contains(","))
                {
                    string[] tempStr = selectedValues.Split(‘,‘);
                    for (int i = 0; i <tempStr.Length; i++)
                    {
                        set.Add(tempStr[i].Trim());
                    }

                }
                else
                {
                    set.Add(selectedValues);
                }
            }

            foreach (SelectListItem item in selectList)
            {
                item.Selected = (item.Value != null) ? set.Contains(item.Value) : set.Contains(item.Text);
                list.Add(item);
            }
            selectList = list;

            HtmlAttributes.Add("type", "checkbox");
            HtmlAttributes.Add("id", id);
            HtmlAttributes.Add("name", name);
            HtmlAttributes.Add("style", "border:none;");

            StringBuilder stringBuilder = new StringBuilder();

            foreach (SelectListItem selectItem in selectList)
            {
                IDictionary<string, object> newHtmlAttributes = HtmlAttributes.DeepCopy();
                newHtmlAttributes.Add("value", selectItem.Value);
                if (selectItem.Selected)
                {
                    newHtmlAttributes.Add("checked", "checked");
                }

                TagBuilder tagBuilder = new TagBuilder("input");
                tagBuilder.MergeAttributes<string, object>(newHtmlAttributes);
                string inputAllHtml = tagBuilder.ToString(TagRenderMode.SelfClosing);
                string containerFormat = isHorizon ? @"<label> {0}  {1}</label>" : @"<p><label> {0}  {1}</label></p>";
                stringBuilder.AppendFormat(containerFormat,
                   inputAllHtml, selectItem.Text);
            }
            return MvcHtmlString.Create(stringBuilder.ToString());

        }
        private static IDictionary<string, object> DeepCopy(this IDictionary<string, object> ht)
        {
            Dictionary<string, object> _ht = new Dictionary<string, object>();

            foreach (var p in ht)
            {
                _ht.Add(p.Key, p.Value);
            }
            return _ht;
        }
    }
}

RadioBoxListHelper code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace SHH.Helpers
{
    public static class RadioBoxListHelper
    {
        public static MvcHtmlString RadioBoxList(this HtmlHelper helper, string name)
        {
            return RadioBoxList(helper, name, helper.ViewData[name] as IEnumerable<SelectListItem>, new { });
        }

        public static MvcHtmlString RadioBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> selectList)
        {
            return RadioBoxList(helper, name, selectList, new { });
        }

        public static MvcHtmlString RadioBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> selectList, object htmlAttributes)
        {
            IDictionary<string, object> HtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            HtmlAttributes.Add("type", "radio");
            HtmlAttributes.Add("name", name);

            StringBuilder stringBuilder = new StringBuilder();
            int i = 0;
            int j = 0;
            foreach (SelectListItem selectItem in selectList)
            {
                string id = string.Format("{0}{1}", name, j++);

                IDictionary<string, object> newHtmlAttributes = HtmlAttributes.DeepCopy();
                newHtmlAttributes.Add("value", selectItem.Value);
                newHtmlAttributes.Add("id", id);
                var selectedValue = (selectList as SelectList).SelectedValue;
                if (selectedValue == null)
                {
                    if (i++ == 0)
                        newHtmlAttributes.Add("checked", null);
                }
                else if (selectItem.Value == selectedValue.ToString())
                {
                    newHtmlAttributes.Add("checked", null);
                }

                TagBuilder tagBuilder = new TagBuilder("input");
                tagBuilder.MergeAttributes<string, object>(newHtmlAttributes);
                string inputAllHtml = tagBuilder.ToString(TagRenderMode.SelfClosing);
                stringBuilder.AppendFormat(@" {0}  <label for=‘{2}‘>{1}</label>",
                   inputAllHtml, selectItem.Text, id);
            }
            return MvcHtmlString.Create(stringBuilder.ToString());

        }
        private static IDictionary<string, object> DeepCopy(this IDictionary<string, object> ht)
        {
            Dictionary<string, object> _ht = new Dictionary<string, object>();

            foreach (var p in ht)
            {
                _ht.Add(p.Key, p.Value);
            }
            return _ht;
        }
    }
}

Enumeration to help the class code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SHH.Helpers
{
    /// <summary>
    /// Enumeration helper classes
    /// </summary>
    public class EnumHelper
    {
        /// <summary>
        /// Such as: "enum1, enum2 conversion, enum3" string to the enumeration values
        /// </summary>
        /// <typeparam name="T">Enumeration types</typeparam>
        /// <param name="obj">The enumerated string</param>
        /// <returns></returns>
        public static T Parse<T>(string obj)
        {
            if (string.IsNullOrEmpty(obj))
                return default(T);
            else
                return (T)Enum.Parse(typeof(T), obj);
        }

        public static T TryParse<T>(string obj, T defT = default(T))
        {
            try
            {
                return Parse<T>(obj);
            }
            catch
            {
                return defT;
            }
        }

        public static readonly string ENUM_TITLE_SEPARATOR = ",";
        /// <summary>
        /// According to the enumeration value, return a string describing the
        /// If multiple enumeration, return to the "," separated string
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static string GetEnumTitle(Enum e, Enum language = null)
        {
            if (e == null)
            {
                return "";
            }
            string[] valueArray = e.ToString().Split(ENUM_TITLE_SEPARATOR.ToArray(), StringSplitOptions.RemoveEmptyEntries);
            Type type = e.GetType();
            string ret = "";
            foreach (string enumValue in valueArray)
            {
                System.Reflection.FieldInfo fi = type.GetField(enumValue.Trim());
                if (fi == null)
                    continue;
                EnumTitleAttribute[] attrs = fi.GetCustomAttributes(typeof(EnumTitleAttribute), false) as EnumTitleAttribute[];
                if (attrs != null && attrs.Length > 0 && attrs[0].IsDisplay)
                {
                    ret += attrs[0].Title + ENUM_TITLE_SEPARATOR;
                }
            }
            return ret.TrimEnd(ENUM_TITLE_SEPARATOR.ToArray());
        }

        /// <summary>
        /// According to the enumeration value, return a string describing the
        /// If multiple enumeration, return to the "," separated string
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static string GetAllEnumTitle(Enum e, Enum language = null)
        {
            if (e == null)
            {
                return "";
            }
            string[] valueArray = e.ToString().Split(ENUM_TITLE_SEPARATOR.ToArray(), StringSplitOptions.RemoveEmptyEntries);
            Type type = e.GetType();
            string ret = "";
            foreach (string enumValue in valueArray)
            {
                System.Reflection.FieldInfo fi = type.GetField(enumValue.Trim());
                if (fi == null)
                    continue;
                EnumTitleAttribute[] attrs = fi.GetCustomAttributes(typeof(EnumTitleAttribute), false) as EnumTitleAttribute[];
                if (attrs != null && attrs.Length > 0)
                {
                    ret += attrs[0].Title + ENUM_TITLE_SEPARATOR;
                }
            }
            return ret.TrimEnd(ENUM_TITLE_SEPARATOR.ToArray());
        }

        public static EnumTitleAttribute GetEnumTitleAttribute(Enum e, Enum language = null)
        {
            if (e == null)
            {
                return null;
            }
            string[] valueArray = e.ToString().Split(ENUM_TITLE_SEPARATOR.ToArray(), StringSplitOptions.RemoveEmptyEntries);
            Type type = e.GetType();
            EnumTitleAttribute ret = null;
            foreach (string enumValue in valueArray)
            {
                System.Reflection.FieldInfo fi = type.GetField(enumValue.Trim());
                if (fi == null)
                    continue;
                EnumTitleAttribute[] attrs = fi.GetCustomAttributes(typeof(EnumTitleAttribute), false) as EnumTitleAttribute[];
                if (attrs != null && attrs.Length > 0)
                {
                    ret = attrs[0];
                    break;
                }
            }
            return ret;
        }

        public static string GetDayOfWeekTitle(DayOfWeek day, Enum language = null)
        {
            switch (day)
            {
                case DayOfWeek.Monday:
                    return "Monday";
                case DayOfWeek.Tuesday:
                    return "Tuesday";
                case DayOfWeek.Wednesday:
                    return "Wednesday";
                case DayOfWeek.Thursday:
                    return "Thursday";
                case DayOfWeek.Friday:
                    return "Friday";
                case DayOfWeek.Saturday:
                    return "Saturday";
                case DayOfWeek.Sunday:
                    return "Sunday";
                default:
                    return "";
            }
        }

        /// <summary>
        /// Returns the key value pairs, built for the name of the specified enumeration of EnumTitle and synonym name, value is the enumeration entries
        /// </summary>
        /// <typeparam name="T">Enumeration types</typeparam>
        /// <param name="language"></param>
        /// <returns></returns>
        public static Dictionary<string, T> GetTitleAndSynonyms<T>(Enum language = null) where T : struct
        {
            Dictionary<string, T> ret = new Dictionary<string, T>();
            //Enumeration values
            Array arrEnumValue = typeof(T).GetEnumValues();
            foreach (object enumValue in arrEnumValue)
            {
                System.Reflection.FieldInfo fi = typeof(T).GetField(enumValue.ToString());
                if (fi == null)
                {
                    continue;
                }

                EnumTitleAttribute[] arrEnumTitleAttr = fi.GetCustomAttributes(typeof(EnumTitleAttribute), false) as EnumTitleAttribute[];
                if (arrEnumTitleAttr == null || arrEnumTitleAttr.Length <1 || !arrEnumTitleAttr[0].IsDisplay)
                {
                    continue;
                }

                if (!ret.ContainsKey(arrEnumTitleAttr[0].Title))
                {
                    ret.Add(arrEnumTitleAttr[0].Title, (T)enumValue);
                }

                if (arrEnumTitleAttr[0].Synonyms == null || arrEnumTitleAttr[0].Synonyms.Length <1)
                {
                    continue;
                }

                foreach (string s in arrEnumTitleAttr[0].Synonyms)
                {
                    if (!ret.ContainsKey(s))
                    {
                        ret.Add(s, (T)enumValue);
                    }
                }
            }//using
            return ret;
        }

        /// <summary>
        /// Based on the enumeration to obtain contains all all values and describe the hash table, the text is composed by the application in the enumeration values on the EnumTitleAttribute set
        /// </summary>
        /// <returns></returns>
        public static Dictionary<T, string> GetItemList<T>(Enum language = null) where T : struct
        {
            return GetItemValueList<T, T>(false, language);
        }

        /// <summary>
        /// Based on the enumeration to obtain contains all all values and describe the hash table, the text is composed by the application in the enumeration values on the EnumTitleAttribute set
        /// </summary>
        /// <returns></returns>
        public static Dictionary<T, string> GetAllItemList<T>(Enum language = null) where T : struct
        {
            return GetItemValueList<T, T>(true, language);
        }

        /// <summary>
        /// Access to enumerate all the title, the text is composed by the application in the enumeration values on the EnumTitleAttribute set
        /// </summary>
        /// <typeparam name="T">Enumeration types</typeparam>
        /// <param name="language">Language</param>
        /// <returns></returns>
        public static Dictionary<int, string> GetItemValueList<T>(Enum language = null) where T : struct
        {
            return GetItemValueList<T, int>(false, language);
        }

        /// <summary>
        /// Access to enumerate all the title, the text is composed by the application in the enumeration values on the EnumTitleAttribute set
        /// </summary>
        /// <typeparam name="T">Enumeration types</typeparam>
        /// <param name="isAll">Whether to build the "all"</param>
        /// <param name="language">Language</param>
        /// <returns></returns>
        public static Dictionary<TKey, string> GetItemValueList<T, TKey>(bool isAll, Enum language = null) where T : struct
        {
            if (!typeof(T).IsEnum)
            {
                throw new Exception("The parameter must be enumerated!");
            }
            Dictionary<TKey, string> ret = new Dictionary<TKey, string>();

            var titles = EnumHelper.GetItemAttributeList<T>().OrderBy(t => t.Value.Order);
            foreach (var t in titles)
            {
                if (!isAll && (!t.Value.IsDisplay || t.Key.ToString() == "None"))
                    continue;

                if (t.Key.ToString() == "None" && isAll)
                {
                    ret.Add((TKey)(object)t.Key, "All");
                }
                else
                {
                    if (!string.IsNullOrEmpty(t.Value.Title))
                        ret.Add((TKey)(object)t.Key, t.Value.Title);
                }
            }

            return ret;
        }

        public static List<T> GetItemKeyList<T>(Enum language = null) where T : struct
        {
            List<T> list = new List<T>();
            Array array = typeof(T).GetEnumValues();
            foreach (object t in array)
            {
                list.Add((T)t);
            }
            return list;
        }

        public static Dictionary<T, EnumTitleAttribute> GetItemAttributeList<T>(Enum language = null) where T : struct
        {
            if (!typeof(T).IsEnum)
            {
                throw new Exception("The parameter must be enumerated!");
            }
            Dictionary<T, EnumTitleAttribute> ret = new Dictionary<T, EnumTitleAttribute>();

            Array array = typeof(T).GetEnumValues();
            foreach (object t in array)
            {
                EnumTitleAttribute att = GetEnumTitleAttribute(t as Enum, language);
                if (att != null)
                    ret.Add((T)t, att);
            }

            return ret;
        }

        /// <summary>
        /// Access to enumerate all the title, the text is composed by the application in the enumeration values on the EnumTitleAttribute set
        /// </summary>
        /// <typeparam name="T">Enumeration types</typeparam>
        /// <param name="isAll">Whether to build the "all"</param>
        /// <param name="language">Language</param>
        /// <returns></returns>
        public static Dictionary<TKey, string> GetAllItemValueList<T, TKey>(Enum language = null) where T : struct
        {
            return GetItemValueList<T, TKey>(true, language);
        }

        /// <summary>
        /// Gets an enumeration pairs
        /// </summary>
        /// <typeparam name="TEnum">Enumeration types</typeparam>
        /// <param name="exceptTypes">Exclude the enumeration</param>
        /// <returns></returns>
        public static Dictionary<int, string> GetEnumDictionary<TEnum>(IEnumerable<TEnum> exceptTypes = null) where TEnum : struct
        {
            var dic = GetItemList<TEnum>();

            Dictionary<int, string> dicNew = new Dictionary<int, string>();
            foreach (var d in dic)
            {
                if (exceptTypes != null && exceptTypes.Contains(d.Key))
                {
                    continue;
                }
                dicNew.Add(d.Key.GetHashCode(), d.Value);
            }
            return dicNew;
        }

    }

    public class EnumTitleAttribute : Attribute
    {
        private bool _IsDisplay = true;

        public EnumTitleAttribute(string title, params string[] synonyms)
        {
            Title = title;
            Synonyms = synonyms;
            Order = int.MaxValue;
        }
        public bool IsDisplay { get { return _IsDisplay; } set { _IsDisplay = value; } }
        public string Title { get; set; }
        public string Description { get; set; }
        public string Letter { get; set; }
        /// <summary>
        /// Synonyms
        /// </summary>
        public string[] Synonyms { get; set; }
        public int Category { get; set; }
        public int Order { get; set; }
    }
}

Enumeration data code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SHH.Helpers
{
    public class EnumData
    {
        /// <summary>
        /// Gender
        /// </summary>
        public enum EnumSex
        {
            [EnumTitle("Hello, sir")]
            Sir = 1,

            [EnumTitle("Ma‘am")]
            Miss = 2
        }
        /// <summary>
        /// Make an appointment
        /// </summary>
        public enum EnumBespeakDate
        {
            [EnumTitle("Working days (Monday to Friday)")]
            BespeakDate1 = 1,

            [EnumTitle("The weekend")]
            BespeakDate2 = 2,

            [EnumTitle("Weekdays or weekends")]
            BespeakDate3 = 3
        }
        /// <summary>
        /// Appointments
        /// </summary>
        public enum EnumBespeakTime
        {
            [EnumTitle("Morning")]
            BespeakTime1 = 1,

            [EnumTitle("The afternoon")]
            BespeakTime2 = 2,

            [EnumTitle("Night")]
            BespeakDate3 = 3,

            [EnumTitle("At any time")]
            BespeakDate4= 4
        }

        /// <summary>
        /// The price
        /// </summary>
        public enum EnumPriceGroup
        {
            [EnumTitle("Unlimited", IsDisplay = false)]
            None = 0,

            [EnumTitle("300000 the following")]
            Below30 = 1,

            [EnumTitle("30-50 million")]
            From30To50 = 2,

            [EnumTitle("50-80 million")]
            From50To80 = 3,

            [EnumTitle("80-100 million")]
            From80To100 = 4,

            [EnumTitle("100-150 million")]
            From100To50 = 5,

            [EnumTitle("150-200 million")]
            From150To200 = 6,

            [EnumTitle("More than 2000000")]
            Above200 = 7
        }

        /// <summary>
        /// The measure of area
        /// </summary>
        public enum EnumAcreageGroup
        {

            [EnumTitle("Unlimited", IsDisplay = false)]
            None = 0,

            [EnumTitle("The following 50mm")]
            Below50 = 1,

            [EnumTitle("50-70mm")]
            From50To70 = 2,

            [EnumTitle("70-90mm")]
            From70To90 = 3,

            [EnumTitle("90-120mm")]
            From90To120 = 4,

            [EnumTitle("120-150mm")]
            From120To150 = 5,

            [EnumTitle("150-200mm")]
            From150To200 = 6,

            [EnumTitle("200-300mm")]
            From200To300 = 7,

            [EnumTitle("More than 300mm")]
            Above300 = 8
        }

        /// <summary>
        /// Fangxing two chamber room five room five room above
        /// </summary>
        public enum EnumRoomGroup
        {
            [EnumTitle("Unlimited", IsDisplay = false)]
            None = 0,

            [EnumTitle("A room")]
            Room1 = 1,

            [EnumTitle("Room two")]
            Room2 = 2,

            [EnumTitle("3")]
            Room3 = 3,

            [EnumTitle("Four")]
            Room4 = 4,

            [EnumTitle("Room five")]
            Room5 = 5,

            [EnumTitle("More than five rooms")]
            Above5 = 6
        }
    }
}

Controller code[RadioBox]

            ViewData.Add("EnumPriceGroup", new SelectList(EnumHelper.GetItemValueList<EnumData.EnumPriceGroup>(), "Key", "Value"));
            ViewData.Add("EnumAcreageGroup", new SelectList(EnumHelper.GetItemValueList<EnumData.EnumAcreageGroup>(), "Key", "Value"));
            ViewData.Add("EnumRoomGroup", new SelectList(EnumHelper.GetItemValueList<EnumData.EnumRoomGroup>(), "Key", "Value"));

View code[RadioBox]

@Html.RadioBoxList("EnumPriceGroup")
@Html.RadioBoxList("EnumAcreageGroup")
@Html.RadioBoxList("EnumRoomGroup")

Controller code[CheckBox]

TagRepository tagrep = new TagRepository(); 
            var tag = tagrep.GetModelList().Where(d=>d.TypeID==1);
            ViewBag.Tags = new SelectList(tag, "TagID", "TagName");
            var tag1 = tagrep.GetModelList().Where(d => d.TypeID == 2);
            ViewBag.Tags1 = new SelectList(tag1, "TagID", "TagName");
            var tag2 = tagrep.GetModelList().Where(d => d.TypeID == 3);
            ViewBag.Tags2 = new SelectList(tag2, "TagID", "TagName");
 /// <summary>
        /// Add GET: /admin/House/Add
        /// </summary>
        /// <param name="model">The entity class</param>
        /// <param name="fc"></param>
        /// <returns></returns>
        [Authorize, HttpPost, ValidateInput(false)]
        public ActionResult Add(House model, FormCollection fc,int[] Tags, int[] Tags1,int[] Tags2)
        {

            model.State = 1;
            model.CreateTime = DateTime.Now;
            HouseControllerrep.SaveOrEditModel(model);

            if (Tags.Length > 0)
            {

                foreach (int gsi in Tags){
                TagHouseMapping thmtag = new TagHouseMapping();
                thmtag.TagID=gsi;
                thmtag.HouseID = model.HouseID;
                thmtag.State = 1;
                thmtag.CreateTime = DateTime.Now;
                TagCrep.SaveOrEditModel(thmtag);
                }
            }
            if (Tags1.Length > 0)
            {

                foreach (int gsi in Tags1)
                {
                    TagHouseMapping thmtag = new TagHouseMapping();
                    thmtag.TagID = gsi;
                    thmtag.HouseID = model.HouseID;
                    thmtag.State = 1;
                    thmtag.CreateTime = DateTime.Now;
                    TagCrep.SaveOrEditModel(thmtag);
                }
            }
            if (Tags2.Length > 0)
            {

                foreach (int gsi in Tags2)
                {
                    TagHouseMapping thmtag = new TagHouseMapping();
                    thmtag.TagID = gsi;
                    thmtag.HouseID = model.HouseID;
                    thmtag.State = 1;
                    thmtag.CreateTime = DateTime.Now;
                    TagCrep.SaveOrEditModel(thmtag);
                }
            }
            return RedirectToAction("Index");
        }
        #endregion

View code[CheckBox]

 @Html.CheckBoxList("Tags")
 @Html.CheckBoxList("Tags1")
 @Html.CheckBoxList("Tags2")

The effect of CheckBoxList

The effect of RadioBoxList

转自:http://www.programering.com/a/MDN2AzNwATQ.html

时间: 2024-11-25 23:53:14

The main reborn ASP.NET MVC4.0: using CheckBoxListHelper and RadioBoxListHelper的相关文章

无废话版本-Asp.net MVC4.0 Rasor的基本用法

最近工作有点忙,好久没写东西了!废话不多说了,进入主题! 1.在页面中输出单一变量时候,只要在C#语句之前加上@符号即可,For example: <p>Now Time:@DateTime.Now</p> 请注意,上述example中虽然使用C#语言撰写代码,但输出单一变量的时候,不需要加上分号: 2.在页面上输出一段含有空白字元或者运算子的结果时,必须在前后加上一个小括号,For example: <p> UserName:@(User.Identity.Name+

ASP.NET MVC4.0+ WebAPI+EasyUI+KnockOutJS快速开发框架 通用权限管理系统

在线演示地址:http://115.28.135.49:8099/ 1.基于 ASP.NET MVC4.0 + WebAPI + EasyUI + Knockout 的架构设计开发 2.采用MVC的框架模式,具有耦合性低.重用性高.生命周期成本低.可维护性高.有利软件工程化管理等优点 3.采用WebAPI,客户端完全摆脱了代理和管道来直接进行交互 4.采用EasyUI前台UI界面插件,可轻松的打造出功能丰富并且美观的UI界面 5.采用Knockout,,提供了一个数据模型与用户UI界面进行关联的

SNF快速开发平台之BS页面展示和九大优点-Asp.net+MVC4.0+WebAPI+EasyUI+Knockout

一)经过多年的实践不断优化.精心维护.运行稳定.功能完善: 能经得起不同实施策略下客户的折腾,能满足各种情况下客户的复杂需求. 二)编码实现简单易懂.符合设计模式等理念: 上手快,见效快.方便维护,能控制软件项目后期维护风险. 三)有严谨的分层理念.完全符合主流的SOA理念架构: 程序可以采用不同的实施策略.架构需求,方便维护.方便扩展. 四)符合RBAC的权限理念.同时也能满足国内小型软件项目的灵活性需求: 不仅符合国际通用标准,又能满足国内的小型软件项目的灵活设置需求. 五)不仅支持多数据库

IIS发布ASP.NET MVC4.0教程

本文主要讲解在微软的IIS Web服务器上发布ASP.NET MVC4.0的项目的方法以及注意事项. 首先介绍如何打开IIS服务器. 打开IIS 在命令行中输入 Inetmgr 既可以打开IIS了,界面如下: 再来谈谈如何查看自己的IIS版本号. IIS版本 在IIS工具的帮助下拉框中,选择 关于internet信息服务 发布 接下来就介绍如何发布ASP.NET MVC4.0项目到IIS8.5 Web服务器上的流程. 首先进入VS中,选择项目中的引用部分,全部选中,将属性中的复制本地全部设为tr

建筑材料系统 ASP.NET MVC4.0 + WebAPI + EasyUI + Knockout 的架构设计开发

框架介绍: 1.基于 ASP.NET MVC4.0 + WebAPI + EasyUI + Knockout 的架构设计开发 2.采用MVC的框架模式,具有耦合性低.重用性高.生命周期成本低.可维护性高.有利软件工程化管理等优点 3.采用WebAPI,客户端完全摆脱了代理和管道来直接进行交互 4.采用EasyUI前台UI界面插件,可轻松的打造出功能丰富并且美观的UI界面 5.采用Knockout,,提供了一个数据模型与用户UI界面进行关联的高层次方式(采用行为驱动开发) 6.数据访问层采用强大的

Asp.Net MVC4.0 官方教程 入门指南之五--控制器访问模型数据

Asp.Net MVC4.0 官方教程 入门指南之五--控制器访问模型数据 在这一节中,你将新创建一个新的 MoviesController类,并编写代码,实现获取影片数据和使用视图模板在浏览器中展现影片数据的功能.在进行下步之前,点击“生成应用程序“对应用程序进行编译.右键单击Controllers文件夹,新建一个名为“MoviesController ”的控制器.在创建窗口各选项如下图所示 点击添加,将创建以下文件和文件夹: 项目的 Controllers 文件夹下新增MoviesContr

Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型

Asp.Net MVC4.0 官方教程 入门指南之四--添加一个模型 在这一节中,你将添加用于管理数据库中电影的类.这些类是ASP.NET MVC应用程序的模型部分. 你将使用.NET Framework框架下的实体框架(Entity Framework)数据访问技术,与模型类协同工作.实体框架(常简称为EF)支持一种称之为编码先行(Code First)的开发模式.编码先行使你通过编写简单的类(简称为POCO类,全称为"plain-old CLR objects."),来创建模型对象

Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图

Asp.Net MVC4.0 官方教程 入门指南之三--添加一个视图 在本节中,您需要修改HelloWorldController类,从而使用视图模板文件,干净优雅的封装生成返回到客户端浏览器HTML的过程. 您将创建一个视图模板文件,其中使用了ASP.NET MVC 3所引入的Razor视图引擎.Razor视图模板文件使用.cshtml文件扩展名,并提供了一个优雅的方式来使用C#语言创建所要输出的HTML.用Razor编写一个视图模板文件时,将所需的字符和键盘敲击数量降到了最低,并实现了快速,

主攻ASP.NET MVC4.0之重生:ASP.NET MVC使用JSONP

原文:主攻ASP.NET MVC4.0之重生:ASP.NET MVC使用JSONP 原文地址 http://www.codeguru.com/csharp/.net/net_asp/using-jsonp-in-asp.net-mvc.htm 1.创建JsonpController public class JsonpController : Controller { // GET: /Jsonp/ VoteUserRepository userrepository = new VoteUser