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

.net MVC中JsonResult 返回类

时间:2016-05-16 14:32:42      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

    /// <summary>
    /// 返回消息类
    /// </summary>
    public class ReturnMessage
    {
        private IDictionary<string, object> m_Data = new Dictionary<string, object>();
        /// <summary>
        /// 响应结果码
        /// 1:成功 0:失败
        /// </summary>
        public string resultCode { get; set; }
        /// <summary>
        /// 若请求失败,此处记录失败原因,若resultCode为1,此处可以为空
        /// </summary>
        public string resultDesc { get; set; }
        /// <summary>
        /// 返回结果
        /// </summary>
        public object result;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="IsSuccess">默认是true还是false</param>
        public ReturnMessage(bool IsSuccess)
        {
            this.IsSuccess = IsSuccess;
        }

        public bool IsContinue { set; get; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ReturnMessage()
        {

        }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 跳转地址
        /// </summary>
        public string RedirectUrl { set; get; }

        /// <summary>
        /// 返回信息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 返回单项数据信息
        /// </summary>
        public string Text { get; set; }

        /// <summary>
        /// 返多项值,以字典形式返回
        /// </summary>
        public IDictionary<string, object> ResultData
        {
            get { return m_Data; }
            set { m_Data = value; }
        }

        /// <summary>
        /// 异常信息
        /// </summary>
        public Exception Exception { get; set; }

        /// <summary>
        /// ToJSONString
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this);
        }
    }

 示例:

  

        [HttpPost]
        public ActionResult DeriveDataList(string MainKey)
        {
            ReturnMessage RM = new ReturnMessage();
            try
            {
                    RM.IsSuccess = true;
            }
            catch (Exception ex)
            {
                RM.IsSuccess = false;
                RM.Message = ex.Message;
            }
            return Json(RM, JsonRequestBehavior.AllowGet);
        }            

 

.net MVC中JsonResult 返回类

标签:

原文地址:http://www.cnblogs.com/zhangqiangflyer/p/5497883.html

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