/// <summary> /// /// </summary> /// <param name="returnValue">返回值</param> /// <param name="returnType">返回类型</param> /// <returns>返回字符串</returns> public static string GetResponseString(object returnValue,Type returnType) { string ret = string.Empty; try { if (returnType.IsSampleType()) { //返回的是简单类型 AjaxResult ajaxResult = new AjaxResult() { Flag = "1", Data = Convert.ToString(returnValue) }; ret = ajaxResult.ToString(); } else { ret = JsonConvert.SerializeObject(returnValue); } } catch (Exception ex) { //遇到异常 AjaxResult errResult = new AjaxResult() { Flag = "0", ErrorMsg = ex.Message }; ret = errResult.ToString(); } return ret; }
/// <summary> /// 得到输出的数据 /// </summary> /// <param name="obj">要输出的值</param> /// <param name="type">要输出的类型</param> /// <returns>返回Json字符串</returns> public override string GetResponse(object obj, Type type) { base.GetResponse(obj, type); string ret = string.Empty; try { if (typeof(byte[]) == type) { //设置取消缓存 base.CurrentContext.Response.Buffer = true; base.CurrentContext.Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0); base.CurrentContext.Response.Expires = 0; base.CurrentContext.Response.CacheControl = "no-cache"; base.CurrentContext.Response.AppendHeader("Pragma", "No-Cache"); base.CurrentContext.Response.BinaryWrite(obj as byte[]); } } catch (Exception ex) { //遇到异常 AjaxResult errResult = new AjaxResult() { Flag = "0", ErrorMsg = ex.Message }; ret = errResult.ToString(); } return ret; }
/// <summary> /// 得到输出的数据 /// </summary> /// <param name="str">要输出的字符串</param> public string GetResponse(string str) { AjaxResult ajaxResult = new AjaxResult() { Flag = "0", ErrorMsg = str }; return _strategy.GetResponse(ajaxResult, typeof(AjaxResult)); }
/// <summary> /// 返回错误 /// </summary> /// <param name="errorMessge"></param> /// <returns></returns> public static string ResponseError(string errorMessge) { //返回错误 AjaxResult errResult = new AjaxResult() { Flag = "0", ErrorMsg = errorMessge }; return errResult.ToString(); }
/// <summary> /// 得到输出的数据 /// </summary> /// <param name="obj">要输出的值</param> /// <param name="type">要输出的类型</param> /// <returns>返回Json字符串</returns> public override string GetResponse(object obj, Type type) { base.GetResponse(obj, type); string ret = string.Empty; try { if (type==typeof(object)) { //如果类型是object 尝试取他实际的类型 type = obj.GetType(); } if (type.IsSampleType()) { //返回的是简单类型 AjaxResult ajaxResult = new AjaxResult() { Flag = "1", Data = Convert.ToString(obj) }; ret = ajaxResult.ToString(); } else if (obj is AjaxResult) { ret = (obj as AjaxResult).ToString(); } else if (obj is JsonpResult) { ret = (obj as JsonpResult).ToString(); } else { ret = JsonMapper.ToJson(obj); } } catch (Exception ex) { //遇到异常 AjaxResult errResult = new AjaxResult() { Flag = "0", ErrorMsg = ex.Message }; ret = errResult.ToString(); } return ret; }
public MethodNotFoundOrInvalidException(AjaxResult ajaxResult) : base(ajaxResult) { }
/// <summary> /// 直接将ajax结果类传出来 /// </summary> /// <param name="ajaxResult"></param> public AjaxException(AjaxResult ajaxResult) { this._ajaxResult = ajaxResult; }
public Ajax404Exception(AjaxResult ajaxResult) : base(ajaxResult) { }