将所有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
}