EXTJS FROM表单返回值JSON数据格式,当上传图片的时候特别注意
2011-11-08 23:48
417 查看
当MVC下.EXTJS提交表单返回值的时候.需要返回JSON格式数据,这里重写了ExecuteResult方法对数据进行了JSON转换.
public class FormActionResult : ActionResult
{
public bool Success { get; set; }
public int ErrorCode { get; set; }
public string Message { get; set; }
public string ContentType { get; set; }
public override void ExecuteResult(ControllerContext context)
{
ContentType = ContentType ?? "application/json";
context.HttpContext.Response.ContentType = ContentType;
context.HttpContext.Response.Write(string.Format("{{\"success\":{0},\"errorcode\":{1},\"msg\":\"{2}\"}}", Success.ToString().ToLower(), ErrorCode, string.IsNullOrEmpty(Message) ? string.Empty : Message));
}
}
当FROM表单里面有UPLOAD控件,上传文件的时候,特别注意要把ContentType ,application/json
改成text/html"
public class FormHtmlActionResult : ActionResult
{
public bool Success { get; set; }
public int ErrorCode { get; set; }
public string Message { get; set; }
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/html";
context.HttpContext.Response.Write(string.Format("{{success:{0},errorcode:{1},msg:\"{2}\"}}", Success.ToString().ToLower(), ErrorCode, string.IsNullOrEmpty(Message) ? string.Empty : Message));
}
}
}
public class FormActionResult : ActionResult
{
public bool Success { get; set; }
public int ErrorCode { get; set; }
public string Message { get; set; }
public string ContentType { get; set; }
public override void ExecuteResult(ControllerContext context)
{
ContentType = ContentType ?? "application/json";
context.HttpContext.Response.ContentType = ContentType;
context.HttpContext.Response.Write(string.Format("{{\"success\":{0},\"errorcode\":{1},\"msg\":\"{2}\"}}", Success.ToString().ToLower(), ErrorCode, string.IsNullOrEmpty(Message) ? string.Empty : Message));
}
}
当FROM表单里面有UPLOAD控件,上传文件的时候,特别注意要把ContentType ,application/json
改成text/html"
public class FormHtmlActionResult : ActionResult
{
public bool Success { get; set; }
public int ErrorCode { get; set; }
public string Message { get; set; }
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/html";
context.HttpContext.Response.Write(string.Format("{{success:{0},errorcode:{1},msg:\"{2}\"}}", Success.ToString().ToLower(), ErrorCode, string.IsNullOrEmpty(Message) ? string.Empty : Message));
}
}
}
相关文章推荐
- var dataObj=eval("("+data+")");//转换为json对象(解决在ajax返回json格式数据的时候明明正确的获取了返回值但是却就是进不去success方法的问题。格式错误)
- ExtJS fileupload组件上传文件后从服务端解析JSON格式数据
- Ueditor图片上传成功后,返回json数据格式
- android使用json数据格式同时上传图片和文本
- 【原创】c#讲数据库数据转换为json格式(使用extjs,easyui中的datagrid)
- JavaScript - AJAX 通过 FormData 上传 form 表单中的所有数据(text 文本,files 图片等二进制文件)
- Struts1基于Json数据格式的ExtJs单选树(Struts1+Spring+Hibernate)
- struts2 + ajax(由前台的form提交数据到后台,再根据form所调用返回获取的后台json格式的数据返回到前端,然后前端用jquery对json数据进行解析)==》》涉及非文件上传的部分
- ajaxFileUpload.js上传图片插件,全浏览器兼容,规避json错误,带文件格式大小拦截
- jquery的ajaxSubmit()异步上传图片并保存表单数据演示代码
- 接口返回值 Json格式数据
- 数据库的字段不够用的时候,可以将数据存为json格式
- JSON编码格式提交表单数据详解
- Extjs 使用Ext.JSON.encode封装json格式的数据
- JSON编码格式提交表单数据详解
- 调试台自动多出现一个'' ,我 用uploadify上传图片时,在给页面写入一个返回值为图片名称的变量的值的时候值的前面始终多出现一个''
- ie8下使用jquery-file-upload上传文件后返回json格式数据提示下载
- json格式 转换的时候 注意是否是类还是数组 微信json为null
- 如何通过表单上传图片数据,PHP后端获取并且保存文件数据
- JSON编码格式提交表单数据详解