zoukankan      html  css  js  c++  java
  • MVC中对controller的抽象

    将所有controller的公共属性和方法提取出来,放到一个controller基类里,共其它controller使用,这无疑不是一个好的选择,以下是我的项目中controller层的抽象,分享一下代码:

    /// <summary>
        /// Controller基类
        /// </summary>
        public abstract class ControllerBase : Controller
        {

            #region Fields

            #endregion

            #region Constructor

            #endregion

            #region Properties
            /// <summary>
            /// 通用信息(一般由service层返回的)
            /// </summary>
            protected Entity.VMessage VMessage { get; set; }
            #endregion

            #region Protected Consts
            /// <summary>
            /// 每页显示的记录数
            /// </summary>
            protected const int PAGESIZE = 10;
            #endregion

            #region Protected virtual Properties
            /// <summary>
            /// 查询器属性
            /// </summary>
            protected virtual Entity.VPredication vp { get; set; }
            /// <summary>
            /// 分页结构属性
            /// </summary>
            protected virtual Entity.PagingParam pp { get; set; }
            #endregion

            #region Protected virtual Methods
            /// <summary>
            /// 操作后,显示的提示成功或失败的信息
            /// author:zzl
            /// </summary>
            /// <param name="msg">提示信息,操作成功或操作失败</param>
            /// <param name="url">点击返回列表后,所进入的地址</param>
            /// <returns></returns>
            protected virtual string DisplayMsg(string msg, string url)
            {
                string message = string.Format("<div style='color:red;font-size:14px;background:rgb(244,250,251);border:rgb(187,221,229) 1px solid;margin:3px;padding:3px'>{0},<a href='{1}'>返回列表</a></div>", msg, url);
                return message;
            }
            protected virtual string DisplayMsg(string msg)
            {
                string message = string.Format("<div style='color:red;font-size:14px;background:rgb(244,250,251);border:rgb(187,221,229) 1px solid;margin:3px;padding:3px'>{0}</div>", msg);
                return message;
            }
            #endregion

       #endregion

        }

  • 相关阅读:
    【一天一道兼容性】之——IE6下fixed失效
    【前端重构技能天赋】(三)——最终篇
    Putty中文乱码问题
    Cygwin Application initialization failed: no display name and no $DISPLAY environment
    c++中的string用法(二)
    在win7下面使用cygwin,并且安装使用git,以及git简明教程
    vi 一些命令(备忘,自己用的)
    对C++中string类型的总结
    ofstream和ifstream详细用法
    写第一个shell脚本,遇到的问题总结整理。
  • 原文地址:https://www.cnblogs.com/lori/p/2275160.html
Copyright © 2011-2022 走看看